Skip to content

Commit

Permalink
refactor(schematics): update schematics to use the new get token sign…
Browse files Browse the repository at this point in the history
…ature (#1969)

Closes #1968
  • Loading branch information
itayod authored and brandonroberts committed Jun 25, 2019
1 parent 1b59cb1 commit 187996f
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('<%= classify(name) %>Effects', () => {
]
});

effects = TestBed.get(<%= classify(name) %>Effects);
effects = TestBed.get<<%= classify(name) %>Effects>(<%= classify(name) %>Effects);
});

it('should be created', () => {
Expand Down
14 changes: 14 additions & 0 deletions modules/effects/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,18 @@ describe('Effect ng-add Schematic', () => {
files.indexOf(`${projectPath}/src/app/effects/foo.effects.ts`)
).toBeGreaterThanOrEqual(0);
});

it('should inject the effect service correctly', async () => {
const options = { ...defaultOptions, spec: true };
const tree = await schematicRunner
.runSchematicAsync('ng-add', options, appTree)
.toPromise();
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.effects.spec.ts`
);

expect(content).toMatch(
/effects = TestBed\.get<FooEffects>\(FooEffects\);/
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('<%= classify(name) %>Component', () => {
beforeEach(() => {
fixture = TestBed.createComponent(<%= classify(name) %>Component);
component = fixture.componentInstance;
store = TestBed.get(Store);
store = TestBed.get<Store>(Store);

spyOn(store, 'dispatch').and.callThrough();
fixture.detectChanges();
Expand Down
11 changes: 11 additions & 0 deletions modules/schematics/src/container/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,15 @@ describe('Container Schematic', () => {
/import { Store, StoreModule } from '@ngrx\/store';/
);
});

it('should inject Store correctly', async () => {
const options = { ...defaultOptions, spec: true };
const tree = await schematicRunner
.runSchematicAsync('container', options, appTree)
.toPromise();
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.spec.ts`
);
expect(content).toMatch(/store = TestBed\.get<Store>\(Store\);/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('<%= classify(name) %>Effects', () => {
]
});

effects = TestBed.get(<%= classify(name) %>Effects);
effects = TestBed.get<<%= classify(name) %>Effects>(<%= classify(name) %>Effects);
});

it('should be created', () => {
Expand Down
14 changes: 14 additions & 0 deletions modules/schematics/src/effect/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,18 @@ describe('Effect Schematic', () => {
/loadFoos\$ = createEffect\(\(\) => this.actions\$.pipe\(/
);
});

it('should inject the effect service correctly', async () => {
const options = { ...defaultOptions, spec: true };
const tree = await schematicRunner
.runSchematicAsync('effect', options, appTree)
.toPromise();
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.effects.spec.ts`
);

expect(content).toMatch(
/effects = TestBed\.get<FooEffects>\(FooEffects\);/
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('Auth Guard', () => {
providers: [AuthGuard, provideMockStore()],
});

store = TestBed.get(Store);
guard = TestBed.get(AuthGuard);
store = TestBed.get<Store>(Store);
guard = TestBed.get<AuthGuard>(AuthGuard);

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

expect(guard.canActivate()).toBeObservable(expected);
});
});
});
12 changes: 6 additions & 6 deletions projects/ngrx.io/content/guide/effects/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('My Effects', () => {
],
});

effects = TestBed.get(MyEffects);
effects = TestBed.get&lt;MyEffects&gt;(MyEffects);
});

it('should work', () => {
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('My Effects', () => {
],
});

effects = TestBed.get(MyEffects);
effects = TestBed.get&lt;MyEffects&gt;(MyEffects);
});

it('should work', () => {
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('My Effects', () => {
],
});

effects = TestBed.get(MyEffects);
effects = TestBed.get&lt;MyEffects&gt;(MyEffects);
metadata = getEffectsMetadata(effects);
});

Expand Down Expand Up @@ -258,9 +258,9 @@ describe('CollectionEffects', () => {
],
});

effects = TestBed.get(CollectionEffects);
actions$ = TestBed.get(Actions);
store = TestBed.get(Store);
effects = TestBed.get&lt;CollectionEffects&gt;(CollectionEffects);
actions$ = TestBed.get&lt;Actions&gt;(Actions);
store = TestBed.get&lt;Store&gt;(Store);
});

describe('addBookToCollectionSuccess$', () => {
Expand Down
6 changes: 3 additions & 3 deletions projects/ngrx.io/content/guide/store/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('Auth Guard', () => {
],
});

guard = TestBed.get(AuthGuard);
store = TestBed.get(Store);
store = TestBed.get&lt;Store&gt(Store);
guard = TestBed.get&lt;AuthGuard&gt;(AuthGuard);
});

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

store = TestBed.get(Store);
store = TestBed.get&lt;Store&gt(Store);

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

Expand Down

0 comments on commit 187996f

Please sign in to comment.