Skip to content

Commit d59e4c0

Browse files
authored
feat: 🎸 add componentImports for SpectatorRouting (#718)
* feat: 🎸 add SpectatorRouting componentImports add componentImports for SpectatorRouting βœ… Closes: #715 * test: πŸ’ componentImports for jest and vitest add missing componentImports for jest and vitest
1 parent 38b036c commit d59e4c0

File tree

4 files changed

+163
-1
lines changed

4 files changed

+163
-1
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {
2+
createComponentFactory,
3+
createHostFactory,
4+
createRoutingFactory,
5+
Spectator,
6+
SpectatorHost,
7+
SpectatorRouting,
8+
} from '@ngneat/spectator/jest';
9+
import { StandaloneComponent } from '../../../../test/standalone/component/standalone.component';
10+
import {
11+
MockStandaloneChildComponent,
12+
StandaloneChildComponent,
13+
StandaloneWithImportsComponent,
14+
} from '../../../../test/standalone/component/standalone-with-imports.component';
15+
16+
describe('StandaloneWithImportsComponent', () => {
17+
describe('with Spectator', () => {
18+
let spectator: Spectator<StandaloneWithImportsComponent>;
19+
20+
const createComponent = createComponentFactory({
21+
component: StandaloneWithImportsComponent,
22+
componentImports: [[StandaloneChildComponent, MockStandaloneChildComponent]],
23+
});
24+
25+
beforeEach(() => {
26+
spectator = createComponent();
27+
});
28+
29+
it('should render a StandaloneComponent with overridden import', () => {
30+
expect(spectator.query('#child-standalone')).toContainText('Mocked!');
31+
});
32+
});
33+
34+
describe('with SpectatorHost', () => {
35+
let host: SpectatorHost<StandaloneComponent>;
36+
37+
const createHost = createHostFactory({
38+
component: StandaloneWithImportsComponent,
39+
template: `<app-standalone-with-imports />`,
40+
componentImports: [[StandaloneChildComponent, MockStandaloneChildComponent]],
41+
});
42+
43+
beforeEach(() => {
44+
host = createHost();
45+
});
46+
47+
it('should render a StandaloneComponent', () => {
48+
expect(host.query('#child-standalone')).toContainText('Mocked!');
49+
});
50+
});
51+
52+
describe('with SpectatorRouting', () => {
53+
let spectator: SpectatorRouting<StandaloneWithImportsComponent>;
54+
55+
const createComponent = createRoutingFactory({
56+
component: StandaloneWithImportsComponent,
57+
componentImports: [[StandaloneChildComponent, MockStandaloneChildComponent]],
58+
});
59+
60+
beforeEach(() => {
61+
spectator = createComponent();
62+
});
63+
64+
it('should render a StandaloneComponent', () => {
65+
expect(spectator.query('#child-standalone')).toContainText('Mocked!');
66+
});
67+
});
68+
});

β€Žprojects/spectator/src/lib/spectator-routing/create-factory.tsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { setProps } from '../internals/query';
77
import * as customMatchers from '../matchers';
88
import {
99
overrideComponentIfProviderOverridesSpecified,
10+
overrideComponentImports,
1011
overrideComponents,
1112
overrideDirectives,
1213
overrideModules,
@@ -52,6 +53,7 @@ export function createRoutingFactory<C>(typeOrOptions: Type<C> | SpectatorRoutin
5253
overridePipes(options);
5354

5455
overrideComponentIfProviderOverridesSpecified(options);
56+
overrideComponentImports(options);
5557
});
5658

5759
return (overrides?: SpectatorRoutingOverrides<C>) => {

β€Žprojects/spectator/test/standalone/component/standalone-with-imports.component.spec.tsβ€Ž

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { createComponentFactory, createHostFactory, Spectator, SpectatorHost } from '@ngneat/spectator';
1+
import {
2+
createComponentFactory,
3+
createHostFactory,
4+
createRoutingFactory,
5+
Spectator,
6+
SpectatorHost,
7+
SpectatorRouting,
8+
} from '@ngneat/spectator';
29
import { StandaloneComponent } from './standalone.component';
310
import {
411
MockStandaloneChildComponent,
@@ -41,4 +48,21 @@ describe('StandaloneWithImportsComponent', () => {
4148
expect(host.query('#child-standalone')).toContainText('Mocked!');
4249
});
4350
});
51+
52+
describe('with SpectatorRouting', () => {
53+
let spectator: SpectatorRouting<StandaloneWithImportsComponent>;
54+
55+
const createComponent = createRoutingFactory({
56+
component: StandaloneWithImportsComponent,
57+
componentImports: [[StandaloneChildComponent, MockStandaloneChildComponent]],
58+
});
59+
60+
beforeEach(() => {
61+
spectator = createComponent();
62+
});
63+
64+
it('should render a StandaloneComponent', () => {
65+
expect(spectator.query('#child-standalone')).toContainText('Mocked!');
66+
});
67+
});
4468
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {
2+
createComponentFactory,
3+
createHostFactory,
4+
createRoutingFactory,
5+
Spectator,
6+
SpectatorHost,
7+
SpectatorRouting,
8+
} from '@ngneat/spectator/vitest';
9+
import { StandaloneComponent } from '../../../../test/standalone/component/standalone.component';
10+
import {
11+
MockStandaloneChildComponent,
12+
StandaloneChildComponent,
13+
StandaloneWithImportsComponent,
14+
} from '../../../../test/standalone/component/standalone-with-imports.component';
15+
16+
describe('StandaloneWithImportsComponent', () => {
17+
describe('with Spectator', () => {
18+
let spectator: Spectator<StandaloneWithImportsComponent>;
19+
20+
const createComponent = createComponentFactory({
21+
component: StandaloneWithImportsComponent,
22+
componentImports: [[StandaloneChildComponent, MockStandaloneChildComponent]],
23+
});
24+
25+
beforeEach(() => {
26+
spectator = createComponent();
27+
});
28+
29+
it('should render a StandaloneComponent with overridden import', () => {
30+
expect(spectator.query('#child-standalone')).toContainText('Mocked!');
31+
});
32+
});
33+
34+
describe('with SpectatorHost', () => {
35+
let host: SpectatorHost<StandaloneComponent>;
36+
37+
const createHost = createHostFactory({
38+
component: StandaloneWithImportsComponent,
39+
template: `<app-standalone-with-imports />`,
40+
componentImports: [[StandaloneChildComponent, MockStandaloneChildComponent]],
41+
});
42+
43+
beforeEach(() => {
44+
host = createHost();
45+
});
46+
47+
it('should render a StandaloneComponent', () => {
48+
expect(host.query('#child-standalone')).toContainText('Mocked!');
49+
});
50+
});
51+
52+
describe('with SpectatorRouting', () => {
53+
let spectator: SpectatorRouting<StandaloneWithImportsComponent>;
54+
55+
const createComponent = createRoutingFactory({
56+
component: StandaloneWithImportsComponent,
57+
componentImports: [[StandaloneChildComponent, MockStandaloneChildComponent]],
58+
});
59+
60+
beforeEach(() => {
61+
spectator = createComponent();
62+
});
63+
64+
it('should render a StandaloneComponent', () => {
65+
expect(spectator.query('#child-standalone')).toContainText('Mocked!');
66+
});
67+
});
68+
});

0 commit comments

Comments
Β (0)