vitest-browser-angular 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -23
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/{pure-J6VXh4xd.mjs → pure-C8IyvQ5e.mjs} +5 -3
- package/dist/pure-HXi6YW9E.d.mts +30 -0
- package/dist/pure.d.mts +2 -2
- package/dist/pure.mjs +1 -1
- package/dist/setup-N1YCbpUn.mjs +18075 -0
- package/dist/setup-zones.d.mts +1 -2
- package/dist/setup-zones.mjs +29541 -3
- package/dist/setup.d.mts +15 -1
- package/dist/setup.mjs +1 -1
- package/package.json +17 -13
- package/dist/pure-DuuxgQMT.d.mts +0 -34
- package/dist/setup-CcdUOv69.mjs +0 -10
package/README.md
CHANGED
|
@@ -8,32 +8,13 @@ Render Angular components in VItest Browser Mode.
|
|
|
8
8
|
pnpm add -D vitest-browser-angular
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## Setup Test Environment
|
|
11
|
+
## Setup Test Environment
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
// vitest.config.ts
|
|
15
|
-
|
|
16
|
-
import { playwright } from '@vitest/browser-playwright';
|
|
17
|
-
|
|
18
|
-
export default defineConfig({
|
|
19
|
-
test: {
|
|
20
|
-
globals: true,
|
|
21
|
-
|
|
22
|
-
// 👇 This is what you need to add
|
|
23
|
-
setupFiles: ['vitest-browser-angular/setup-zones'],
|
|
24
|
-
|
|
25
|
-
browser: {
|
|
26
|
-
enabled: true,
|
|
27
|
-
provider: playwright(),
|
|
28
|
-
instances: [{ browser: 'chromium' }],
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
```
|
|
13
|
+
To set up your test environment (with Zone.js or Zoneless), use `@analogjs/vitest-angular`'s `setupTestBed()` function.
|
|
33
14
|
|
|
34
|
-
|
|
15
|
+
**Important:** Make sure to use `{ browserMode: true }` when calling `setupTestBed()` to enable Vitest browser mode's visual test preview functionality.
|
|
35
16
|
|
|
36
|
-
|
|
17
|
+
For detailed setup instructions for both Zone.js and Zoneless configurations, please refer to the [Analog Vitest documentation](https://analogjs.org/docs/features/testing/vitest).
|
|
37
18
|
|
|
38
19
|
## Usage
|
|
39
20
|
|
|
@@ -54,6 +35,37 @@ test('render', async () => {
|
|
|
54
35
|
});
|
|
55
36
|
```
|
|
56
37
|
|
|
38
|
+
## Inputs
|
|
39
|
+
|
|
40
|
+
Pass input values to components using the `inputs` option:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { Component, input } from '@angular/core';
|
|
44
|
+
|
|
45
|
+
@Component({
|
|
46
|
+
template: '<h2>{{ name() }}</h2><p>Price: ${{ price() }}</p>',
|
|
47
|
+
standalone: true,
|
|
48
|
+
})
|
|
49
|
+
export class ProductComponent {
|
|
50
|
+
name = input('Unknown Product');
|
|
51
|
+
price = input(0);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
test('render with inputs', async () => {
|
|
55
|
+
const { component } = await render(ProductComponent, {
|
|
56
|
+
inputs: {
|
|
57
|
+
name: 'Laptop',
|
|
58
|
+
price: 1299.99,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await expect.element(component).toHaveTextContent('Laptop');
|
|
63
|
+
await expect.element(component).toHaveTextContent('$1299.99');
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Works with both signal-based inputs (`input()`) and `@Input()` decorators.
|
|
68
|
+
|
|
57
69
|
## Routing
|
|
58
70
|
|
|
59
71
|
### Simple Routing
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { i as RenderResult, n as RenderConfig, o as cleanup, r as RenderFn, s as render, t as Inputs } from "./pure-HXi6YW9E.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
declare module "vitest/browser" {
|
|
@@ -7,4 +7,4 @@ declare module "vitest/browser" {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
//#endregion
|
|
10
|
-
export { type RenderFn, type RenderResult, cleanup, render };
|
|
10
|
+
export { type Inputs, type RenderConfig, type RenderFn, type RenderResult, cleanup, render };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { page } from "vitest/browser";
|
|
2
|
+
import { inputBinding } from "@angular/core";
|
|
2
3
|
import { TestBed, ɵgetCleanupHook } from "@angular/core/testing";
|
|
3
4
|
import { Router, provideRouter } from "@angular/router";
|
|
4
5
|
import { RouterTestingHarness } from "@angular/router/testing";
|
|
@@ -20,7 +21,8 @@ async function render(componentClass, config) {
|
|
|
20
21
|
renderResult.routerHarness = await RouterTestingHarness.create(typeof config.withRouting === "boolean" ? void 0 : config.withRouting.initialRoute);
|
|
21
22
|
renderResult.router = TestBed.inject(Router);
|
|
22
23
|
}
|
|
23
|
-
const
|
|
24
|
+
const bindings = Object.entries(config?.inputs ?? {}).map(([key, value]) => inputBinding(key, () => value));
|
|
25
|
+
const fixture = TestBed.createComponent(componentClass, { bindings });
|
|
24
26
|
fixture.autoDetectChanges();
|
|
25
27
|
await fixture.whenStable();
|
|
26
28
|
const component = page.elementLocator(fixture.nativeElement);
|
|
@@ -31,8 +33,8 @@ async function render(componentClass, config) {
|
|
|
31
33
|
component
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
|
-
function cleanup(
|
|
35
|
-
return ɵgetCleanupHook(
|
|
36
|
+
function cleanup(shouldTeardown = false) {
|
|
37
|
+
return ɵgetCleanupHook(shouldTeardown)();
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
//#endregion
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Locator } from "vitest/browser";
|
|
2
|
+
import { EnvironmentProviders, InputSignal, Provider, Type } from "@angular/core";
|
|
3
|
+
import { ComponentFixture } from "@angular/core/testing";
|
|
4
|
+
import { Router, Routes } from "@angular/router";
|
|
5
|
+
import { RouterTestingHarness } from "@angular/router/testing";
|
|
6
|
+
|
|
7
|
+
//#region src/pure.d.ts
|
|
8
|
+
interface RoutingConfig {
|
|
9
|
+
routes: Routes;
|
|
10
|
+
initialRoute?: string;
|
|
11
|
+
}
|
|
12
|
+
type Inputs<CMP_TYPE extends Type<unknown>> = Partial<{ [PROP in keyof InstanceType<CMP_TYPE> as InstanceType<CMP_TYPE>[PROP] extends InputSignal<unknown> ? PROP : never]: InstanceType<CMP_TYPE>[PROP] extends InputSignal<infer VALUE> ? VALUE : never }>;
|
|
13
|
+
interface RenderConfig<CMP_TYPE extends Type<unknown> = Type<unknown>> {
|
|
14
|
+
inputs?: Inputs<CMP_TYPE>;
|
|
15
|
+
withRouting?: RoutingConfig | boolean;
|
|
16
|
+
providers?: Array<Provider | EnvironmentProviders>;
|
|
17
|
+
imports?: unknown[];
|
|
18
|
+
}
|
|
19
|
+
interface RenderResult<T> {
|
|
20
|
+
fixture: ComponentFixture<T>;
|
|
21
|
+
component: Locator;
|
|
22
|
+
componentClassInstance: T;
|
|
23
|
+
routerHarness?: RouterTestingHarness;
|
|
24
|
+
router?: Router;
|
|
25
|
+
}
|
|
26
|
+
type RenderFn = <T>(component: Type<T>, config?: RenderConfig<Type<T>>) => Promise<RenderResult<T>>;
|
|
27
|
+
declare function render<T>(componentClass: Type<T>, config?: RenderConfig<Type<T>>): Promise<RenderResult<T>>;
|
|
28
|
+
declare function cleanup(shouldTeardown?: boolean): void;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { RoutingConfig as a, RenderResult as i, RenderConfig as n, cleanup as o, RenderFn as r, render as s, Inputs as t };
|
package/dist/pure.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
export { RenderFn, RenderResult, cleanup, render };
|
|
1
|
+
import { a as RoutingConfig, i as RenderResult, n as RenderConfig, o as cleanup, r as RenderFn, s as render, t as Inputs } from "./pure-HXi6YW9E.mjs";
|
|
2
|
+
export { Inputs, RenderConfig, RenderFn, RenderResult, RoutingConfig, cleanup, render };
|
package/dist/pure.mjs
CHANGED