Skip to content

Commit 187996f

Browse files
itayodbrandonroberts
authored andcommitted
refactor(schematics): update schematics to use the new get token signature (#1969)
Closes #1968
1 parent 1b59cb1 commit 187996f

File tree

9 files changed

+54
-15
lines changed

9 files changed

+54
-15
lines changed

modules/effects/schematics/ng-add/files/__name@dasherize@if-flat__/__name@dasherize__.effects.spec.ts.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('<%= classify(name) %>Effects', () => {
1616
]
1717
});
1818

19-
effects = TestBed.get(<%= classify(name) %>Effects);
19+
effects = TestBed.get<<%= classify(name) %>Effects>(<%= classify(name) %>Effects);
2020
});
2121

2222
it('should be created', () => {

modules/effects/schematics/ng-add/index.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,18 @@ describe('Effect ng-add Schematic', () => {
180180
files.indexOf(`${projectPath}/src/app/effects/foo.effects.ts`)
181181
).toBeGreaterThanOrEqual(0);
182182
});
183+
184+
it('should inject the effect service correctly', async () => {
185+
const options = { ...defaultOptions, spec: true };
186+
const tree = await schematicRunner
187+
.runSchematicAsync('ng-add', options, appTree)
188+
.toPromise();
189+
const content = tree.readContent(
190+
`${projectPath}/src/app/foo/foo.effects.spec.ts`
191+
);
192+
193+
expect(content).toMatch(
194+
/effects = TestBed\.get<FooEffects>\(FooEffects\);/
195+
);
196+
});
183197
});

modules/schematics/src/container/files/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('<%= classify(name) %>Component', () => {
2020
beforeEach(() => {
2121
fixture = TestBed.createComponent(<%= classify(name) %>Component);
2222
component = fixture.componentInstance;
23-
store = TestBed.get(Store);
23+
store = TestBed.get<Store>(Store);
2424

2525
spyOn(store, 'dispatch').and.callThrough();
2626
fixture.detectChanges();

modules/schematics/src/container/index.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,15 @@ describe('Container Schematic', () => {
121121
/import { Store, StoreModule } from '@ngrx\/store';/
122122
);
123123
});
124+
125+
it('should inject Store correctly', async () => {
126+
const options = { ...defaultOptions, spec: true };
127+
const tree = await schematicRunner
128+
.runSchematicAsync('container', options, appTree)
129+
.toPromise();
130+
const content = tree.readContent(
131+
`${projectPath}/src/app/foo/foo.component.spec.ts`
132+
);
133+
expect(content).toMatch(/store = TestBed\.get<Store>\(Store\);/);
134+
});
124135
});

modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.spec.ts.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('<%= classify(name) %>Effects', () => {
1616
]
1717
});
1818

19-
effects = TestBed.get(<%= classify(name) %>Effects);
19+
effects = TestBed.get<<%= classify(name) %>Effects>(<%= classify(name) %>Effects);
2020
});
2121

2222
it('should be created', () => {

modules/schematics/src/effect/index.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,18 @@ describe('Effect Schematic', () => {
370370
/loadFoos\$ = createEffect\(\(\) => this.actions\$.pipe\(/
371371
);
372372
});
373+
374+
it('should inject the effect service correctly', async () => {
375+
const options = { ...defaultOptions, spec: true };
376+
const tree = await schematicRunner
377+
.runSchematicAsync('effect', options, appTree)
378+
.toPromise();
379+
const content = tree.readContent(
380+
`${projectPath}/src/app/foo/foo.effects.spec.ts`
381+
);
382+
383+
expect(content).toMatch(
384+
/effects = TestBed\.get<FooEffects>\(FooEffects\);/
385+
);
386+
});
373387
});

projects/ngrx.io/content/examples/testing-store/src/app/auth-guard.service.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ describe('Auth Guard', () => {
1515
providers: [AuthGuard, provideMockStore()],
1616
});
1717

18-
store = TestBed.get(Store);
19-
guard = TestBed.get(AuthGuard);
18+
store = TestBed.get<Store>(Store);
19+
guard = TestBed.get<AuthGuard>(AuthGuard);
2020

2121
loggedIn = store.overrideSelector(fromAuth.getLoggedIn, false);
2222
});
@@ -34,4 +34,4 @@ describe('Auth Guard', () => {
3434

3535
expect(guard.canActivate()).toBeObservable(expected);
3636
});
37-
});
37+
});

projects/ngrx.io/content/guide/effects/testing.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('My Effects', () => {
3434
],
3535
});
3636

37-
effects = TestBed.get(MyEffects);
37+
effects = TestBed.get&lt;MyEffects&gt;(MyEffects);
3838
});
3939

4040
it('should work', () => {
@@ -76,7 +76,7 @@ describe('My Effects', () => {
7676
],
7777
});
7878

79-
effects = TestBed.get(MyEffects);
79+
effects = TestBed.get&lt;MyEffects&gt;(MyEffects);
8080
});
8181

8282
it('should work', () => {
@@ -114,7 +114,7 @@ describe('My Effects', () => {
114114
],
115115
});
116116

117-
effects = TestBed.get(MyEffects);
117+
effects = TestBed.get&lt;MyEffects&gt;(MyEffects);
118118
metadata = getEffectsMetadata(effects);
119119
});
120120

@@ -258,9 +258,9 @@ describe('CollectionEffects', () => {
258258
],
259259
});
260260

261-
effects = TestBed.get(CollectionEffects);
262-
actions$ = TestBed.get(Actions);
263-
store = TestBed.get(Store);
261+
effects = TestBed.get&lt;CollectionEffects&gt;(CollectionEffects);
262+
actions$ = TestBed.get&lt;Actions&gt;(Actions);
263+
store = TestBed.get&lt;Store&gt;(Store);
264264
});
265265

266266
describe('addBookToCollectionSuccess$', () => {

projects/ngrx.io/content/guide/store/testing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ describe('Auth Guard', () => {
3838
],
3939
});
4040

41-
guard = TestBed.get(AuthGuard);
42-
store = TestBed.get(Store);
41+
store = TestBed.get&lt;Store&gt(Store);
42+
guard = TestBed.get&lt;AuthGuard&gt;(AuthGuard);
4343
});
4444

4545
it('should return false if the user state is not logged in', () => {
@@ -144,7 +144,7 @@ describe('My Component', () => {
144144
],
145145
});
146146

147-
store = TestBed.get(Store);
147+
store = TestBed.get&lt;Store&gt(Store);
148148

149149
spyOn(store, 'dispatch').and.callThrough();
150150

0 commit comments

Comments
 (0)