From 6adf6eb5e4d8cbda975635fc41d19d993ca47451 Mon Sep 17 00:00:00 2001 From: Sumit Date: Fri, 10 Jan 2020 21:16:59 +0530 Subject: [PATCH] test(component): update usage of TestBed.get to TestBed.inject angular 9 compatibillity changes for TestBed Closes #2240 test(docs): test cases updated in docs TestBed.get replaced by TestBed.inject Closes ##2240 test(component): example tests type fixed TestBed.get replace by TestBed.inject done test(component): test issue fixed angular 9 test upgrade changes done test(component): changes under docs folder is reverted angular 9 test upgrade changes test(component): src tests changes reverted angular 9 test upgrade changes test(component): reverted unnecessary testing changes content folder changes are kept changes test(component): update usage of TestBed.get to TestBed.inject angular 9 compatibillity changes for TestBed Closes #2240 test(docs): test cases updated in docs TestBed.get replaced by TestBed.inject Closes ##2240 test(component): example tests type fixed TestBed.get replace by TestBed.inject done test(component): test issue fixed angular 9 test upgrade changes done test(component): changes under docs folder is reverted angular 9 test upgrade changes test(component): src tests changes reverted angular 9 test upgrade changes test(component): reverted unnecessary testing changes content folder changes are kept changes --- docs/effects/testing.md | 4 +- .../spec/effects/entity-cache-effects.spec.ts | 6 +-- .../entity-definition.service.spec.ts | 2 +- .../related-entity-selectors.spec.ts | 6 +-- .../spec/utils/default-pluralizer.spec.ts | 4 +- ..._name@dasherize__.effects.spec.ts.template | 2 +- .../effects/schematics/ng-add/index.spec.ts | 2 +- modules/effects/spec/effect_sources.spec.ts | 6 +-- .../spec/effects_feature_module.spec.ts | 8 ++-- .../effects/spec/effects_root_module.spec.ts | 4 +- modules/effects/spec/integration.spec.ts | 10 ++-- modules/router-store/spec/integration.spec.ts | 48 +++++++++---------- .../spec/router_store_module.spec.ts | 20 ++++---- ...ame@dasherize__.component.spec.ts.template | 2 +- .../schematics/src/container/index.spec.ts | 2 +- ...ame@dasherize__.component.spec.ts.template | 2 +- ..._name@dasherize__.service.spec.ts.template | 2 +- ..._name@dasherize__.effects.spec.ts.template | 2 +- modules/schematics/src/effect/index.spec.ts | 2 +- .../store-devtools/spec/integration.spec.ts | 6 +-- modules/store-devtools/spec/store.spec.ts | 8 ++-- modules/store/spec/edge.spec.ts | 2 +- modules/store/spec/integration.spec.ts | 16 +++---- modules/store/spec/modules.spec.ts | 6 +-- modules/store/spec/runtime_checks.spec.ts | 10 ++-- modules/store/spec/state.spec.ts | 4 +- modules/store/spec/store.spec.ts | 28 +++++------ modules/store/testing/src/mock_store.ts | 2 +- .../containers/login-page.component.spec.ts | 2 +- .../src/app/auth/effects/auth.effects.spec.ts | 10 ++-- .../auth/services/auth-guard.service.spec.ts | 4 +- .../collection-page.component.spec.ts | 2 +- .../find-book-page.component.spec.ts | 2 +- .../selected-book-page.component.spec.ts | 2 +- .../view-book-page.component.spec.ts | 4 +- .../app/books/effects/book.effects.spec.ts | 6 +-- .../books/effects/collection.effects.spec.ts | 6 +-- .../app/core/effects/router.effects.spec.ts | 4 +- .../src/app/core/effects/user.effects.spec.ts | 2 +- .../services/book-storage.service.spec.ts | 4 +- .../services/google-books.service.spec.ts | 4 +- 41 files changed, 132 insertions(+), 136 deletions(-) diff --git a/docs/effects/testing.md b/docs/effects/testing.md index 7e4bef1f92..80a8ee3d2b 100644 --- a/docs/effects/testing.md +++ b/docs/effects/testing.md @@ -84,7 +84,7 @@ describe('My Effects', () => { ], }); - effects = TestBed.inject(MyEffects); + effects = TestBed.get(MyEffects); }); it('should work', () => { @@ -122,7 +122,7 @@ describe('My Effects', () => { ], }); - effects = TestBed.inject(MyEffects); + effects = TestBed.get(MyEffects); metadata = getEffectsMetadata(effects); }); diff --git a/modules/data/spec/effects/entity-cache-effects.spec.ts b/modules/data/spec/effects/entity-cache-effects.spec.ts index 756467c56c..d6498d3167 100644 --- a/modules/data/spec/effects/entity-cache-effects.spec.ts +++ b/modules/data/spec/effects/entity-cache-effects.spec.ts @@ -65,9 +65,9 @@ describe('EntityCacheEffects (normal testing)', () => { ], }); - actions$ = TestBed.inject(Actions); - effects = TestBed.inject(EntityCacheEffects); - dataService = TestBed.inject(EntityCacheDataService); + actions$ = TestBed.get(Actions); + effects = TestBed.get(EntityCacheEffects); + dataService = TestBed.get(EntityCacheDataService); }); it('should return a SAVE_ENTITIES_SUCCESS with the expected ChangeSet on success', (done: DoneFn) => { diff --git a/modules/data/spec/entity-metadata/entity-definition.service.spec.ts b/modules/data/spec/entity-metadata/entity-definition.service.spec.ts index 53e7bf4034..923f7623dd 100644 --- a/modules/data/spec/entity-metadata/entity-definition.service.spec.ts +++ b/modules/data/spec/entity-metadata/entity-definition.service.spec.ts @@ -37,7 +37,7 @@ describe('EntityDefinitionService', () => { { provide: ENTITY_METADATA_TOKEN, multi: true, useValue: metadataMap }, ], }); - service = TestBed.inject(EntityDefinitionService); + service = TestBed.get(EntityDefinitionService); }); describe('#getDefinition', () => { diff --git a/modules/data/spec/selectors/related-entity-selectors.spec.ts b/modules/data/spec/selectors/related-entity-selectors.spec.ts index 33193cfe76..9d9175d9dd 100644 --- a/modules/data/spec/selectors/related-entity-selectors.spec.ts +++ b/modules/data/spec/selectors/related-entity-selectors.spec.ts @@ -47,9 +47,9 @@ describe('Related-entity Selectors', () => { ], }); - store = TestBed.inject(Store); - eaFactory = TestBed.inject(EntityActionFactory); - entitySelectorsFactory = TestBed.inject(EntitySelectorsFactory); + store = TestBed.get(Store); + eaFactory = TestBed.get(EntityActionFactory); + entitySelectorsFactory = TestBed.get(EntitySelectorsFactory); initializeCache(eaFactory, store); }); diff --git a/modules/data/spec/utils/default-pluralizer.spec.ts b/modules/data/spec/utils/default-pluralizer.spec.ts index 7c8faec8ad..134e70e5bb 100644 --- a/modules/data/spec/utils/default-pluralizer.spec.ts +++ b/modules/data/spec/utils/default-pluralizer.spec.ts @@ -10,7 +10,7 @@ describe('DefaultPluralizer', () => { providers: [{ provide: Pluralizer, useClass: DefaultPluralizer }], }); - pluralizer = TestBed.inject(Pluralizer); + pluralizer = TestBed.get(Pluralizer); }); it('should turn "Hero" to "Heros" because no plural names map', () => { // No map so 'Hero' gets default pluralization @@ -70,7 +70,7 @@ describe('DefaultPluralizer', () => { ], }); - pluralizer = TestBed.inject(Pluralizer); + pluralizer = TestBed.get(Pluralizer); }); it('should pluralize "Villain" which is not in plural names', () => { diff --git a/modules/effects/schematics/ng-add/files/__name@dasherize@if-flat__/__name@dasherize__.effects.spec.ts.template b/modules/effects/schematics/ng-add/files/__name@dasherize@if-flat__/__name@dasherize__.effects.spec.ts.template index cd98099c94..4a7089c41a 100644 --- a/modules/effects/schematics/ng-add/files/__name@dasherize@if-flat__/__name@dasherize__.effects.spec.ts.template +++ b/modules/effects/schematics/ng-add/files/__name@dasherize@if-flat__/__name@dasherize__.effects.spec.ts.template @@ -16,7 +16,7 @@ describe('<%= classify(name) %>Effects', () => { ] }); - effects = TestBed.inject<<%= classify(name) %>Effects>(<%= classify(name) %>Effects); + effects = TestBed.get<<%= classify(name) %>Effects>(<%= classify(name) %>Effects); }); it('should be created', () => { diff --git a/modules/effects/schematics/ng-add/index.spec.ts b/modules/effects/schematics/ng-add/index.spec.ts index bad3120a0c..038c78ac9f 100644 --- a/modules/effects/schematics/ng-add/index.spec.ts +++ b/modules/effects/schematics/ng-add/index.spec.ts @@ -219,7 +219,7 @@ describe('Effects ng-add Schematic', () => { ); expect(content).toMatch( - /effects = TestBed\.inject\(FooEffects\);/ + /effects = TestBed\.get\(FooEffects\);/ ); }); }); diff --git a/modules/effects/spec/effect_sources.spec.ts b/modules/effects/spec/effect_sources.spec.ts index 7874899302..b4117355be 100644 --- a/modules/effects/spec/effect_sources.spec.ts +++ b/modules/effects/spec/effect_sources.spec.ts @@ -30,8 +30,8 @@ describe('EffectSources', () => { ], }); - mockErrorReporter = TestBed.inject(ErrorHandler); - effectSources = TestBed.inject(EffectSources); + mockErrorReporter = TestBed.get(ErrorHandler); + effectSources = TestBed.get(EffectSources); spyOn(mockErrorReporter, 'handleError'); }); @@ -54,7 +54,7 @@ describe('EffectSources', () => { effectSources.addEffects(new EffectWithInitAction()); - const store = TestBed.inject(Store); + const store = TestBed.get(Store); expect(store.dispatch).toHaveBeenCalledWith({ type: '[EffectWithInitAction] Init', }); diff --git a/modules/effects/spec/effects_feature_module.spec.ts b/modules/effects/spec/effects_feature_module.spec.ts index cb30bbe2c4..411937db80 100644 --- a/modules/effects/spec/effects_feature_module.spec.ts +++ b/modules/effects/spec/effects_feature_module.spec.ts @@ -40,11 +40,11 @@ describe('Effects Feature Module', () => { ], }); - mockEffectSources = TestBed.inject(EffectsRootModule); + mockEffectSources = TestBed.get(EffectsRootModule); }); it('should add all effects when instantiated', () => { - TestBed.inject(EffectsFeatureModule); + TestBed.get(EffectsFeatureModule); expect(mockEffectSources.addEffects).toHaveBeenCalledWith(sourceA); expect(mockEffectSources.addEffects).toHaveBeenCalledWith(sourceB); @@ -61,8 +61,8 @@ describe('Effects Feature Module', () => { imports: [AppModule], }); - effects = TestBed.inject(FeatureEffects); - store = TestBed.inject(Store); + effects = TestBed.get(FeatureEffects); + store = TestBed.get(Store); }); it('should have the feature state defined to select from the effect', (done: any) => { diff --git a/modules/effects/spec/effects_root_module.spec.ts b/modules/effects/spec/effects_root_module.spec.ts index 7c1e9d7449..19a49600cc 100644 --- a/modules/effects/spec/effects_root_module.spec.ts +++ b/modules/effects/spec/effects_root_module.spec.ts @@ -20,7 +20,7 @@ describe('Effects Root Module', () => { ], }); - const store = TestBed.inject(Store); + const store = TestBed.get(Store); expect(reducer).toHaveBeenCalledWith(foo, { type: INIT, @@ -37,7 +37,7 @@ describe('Effects Root Module', () => { ], }); - const store = TestBed.inject(Store); + const store = TestBed.get(Store); expect(reducer).toHaveBeenCalledWith(foo, { type: INIT, diff --git a/modules/effects/spec/integration.spec.ts b/modules/effects/spec/integration.spec.ts index 0a7ee45126..e865452e79 100644 --- a/modules/effects/spec/integration.spec.ts +++ b/modules/effects/spec/integration.spec.ts @@ -38,9 +38,9 @@ describe('NgRx Effects Integration spec', () => { ], }); - const store = TestBed.inject(Store) as Store; + const store = TestBed.get(Store) as Store; - const effectSources = TestBed.inject(EffectSources) as EffectSources; + const effectSources = TestBed.get(EffectSources) as EffectSources; effectSources.addEffects(new FeatEffectWithIdentifierAndInitAction('one')); effectSources.addEffects(new FeatEffectWithIdentifierAndInitAction('two')); effectSources.addEffects(new FeatEffectWithIdentifierAndInitAction('one')); @@ -81,10 +81,8 @@ describe('NgRx Effects Integration spec', () => { }); it('throws if forRoot() is used more than once', (done: DoneFn) => { - let router: Router = TestBed.inject(Router); - const loader: SpyNgModuleFactoryLoader = TestBed.inject( - NgModuleFactoryLoader - ); + let router: Router = TestBed.get(Router); + const loader: SpyNgModuleFactoryLoader = TestBed.get(NgModuleFactoryLoader); loader.stubbedModules = { feature: FeatModuleWithForRoot }; router.resetConfig([{ path: 'feature-path', loadChildren: 'feature' }]); diff --git a/modules/router-store/spec/integration.spec.ts b/modules/router-store/spec/integration.spec.ts index e1df35309f..61a64350ff 100644 --- a/modules/router-store/spec/integration.spec.ts +++ b/modules/router-store/spec/integration.spec.ts @@ -38,7 +38,7 @@ describe('integration spec', () => { createTestModule({ reducers: { reducer } }); - const router: Router = TestBed.inject(Router); + const router: Router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore(); router @@ -113,7 +113,7 @@ describe('integration spec', () => { ) => state.url !== 'next', }); - const router: Router = TestBed.inject(Router); + const router: Router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore(); const hasRouterState = (action: RouterAction) => @@ -148,7 +148,7 @@ describe('integration spec', () => { createTestModule({ reducers: { reducer } }); - const router: Router = TestBed.inject(Router); + const router: Router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore(); router @@ -192,7 +192,7 @@ describe('integration spec', () => { canActivate: () => false, }); - const router: Router = TestBed.inject(Router); + const router: Router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore(); router @@ -271,8 +271,8 @@ describe('integration spec', () => { config: { stateKey: 'reducer' }, }); - const router: Router = TestBed.inject(Router); - const store: Store = TestBed.inject(Store); + const router: Router = TestBed.get(Router); + const store: Store = TestBed.get(Store); const log = logOfRouterAndActionsAndStore(); router @@ -330,7 +330,7 @@ describe('integration spec', () => { }, }); - const router: Router = TestBed.inject(Router); + const router: Router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore(); router @@ -417,8 +417,8 @@ describe('integration spec', () => { config: { stateKey: 'reducer' }, }); - const router: Router = TestBed.inject(Router); - const store: Store = TestBed.inject(Store); + const router: Router = TestBed.get(Router); + const store: Store = TestBed.get(Store); const log = logOfRouterAndActionsAndStore(); router @@ -460,8 +460,8 @@ describe('integration spec', () => { createTestModule({ reducers: { router: routerReducer, reducer } }); - const router = TestBed.inject(Router); - const store = TestBed.inject(Store); + const router = TestBed.get(Router); + const store = TestBed.get(Store); const log = logOfRouterAndActionsAndStore(); const routerReducerStates: any[] = []; @@ -565,7 +565,7 @@ describe('integration spec', () => { canLoad: () => false, }); - const router = TestBed.inject(Router); + const router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore(); router.navigateByUrl('/load').then((r: boolean) => { @@ -597,7 +597,7 @@ describe('integration spec', () => { canLoad: () => Promise.reject('boom'), }); - const router: Router = TestBed.inject(Router); + const router: Router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore(); router @@ -670,7 +670,7 @@ describe('integration spec', () => { createTestModule({ reducers: { routerReducer, reducer }, providers }); } - const router = TestBed.inject(Router); + const router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore(); router @@ -725,8 +725,8 @@ describe('integration spec', () => { }, }); - const router: Router = TestBed.inject(Router); - const store: Store = TestBed.inject(Store); + const router: Router = TestBed.get(Router); + const store: Store = TestBed.get(Store); const log = logOfRouterAndActionsAndStore(); router @@ -773,7 +773,7 @@ describe('integration spec', () => { config: { stateKey: 'router-reducer' }, }); - const router: Router = TestBed.inject(Router); + const router: Router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore({ stateKey: 'router-reducer' }); router @@ -835,7 +835,7 @@ describe('integration spec', () => { config: { stateKey: (state: any) => state.routerReducer }, }); - const router: Router = TestBed.inject(Router); + const router: Router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore({ stateKey: (state: any) => state.routerReducer, }); @@ -899,8 +899,8 @@ describe('integration spec', () => { config: { stateKey: 'reducer' }, }); - const router: Router = TestBed.inject(Router); - const store = TestBed.inject(Store); + const router: Router = TestBed.get(Router); + const store = TestBed.get(Store); const log = logOfRouterAndActionsAndStore(); store.dispatch({ @@ -956,7 +956,7 @@ describe('integration spec', () => { config: { navigationActionTiming: NavigationActionTiming.PostActivation }, }); - const router: Router = TestBed.inject(Router); + const router: Router = TestBed.get(Router); const log = logOfRouterAndActionsAndStore(); router.navigateByUrl('/').then(() => { @@ -1002,10 +1002,10 @@ function logOfRouterAndActionsAndStore( stateKey: 'reducer', } ): any[] { - const router: Router = TestBed.inject(Router); - const store: Store = TestBed.inject(Store); + const router: Router = TestBed.get(Router); + const store: Store = TestBed.get(Store); // Not using effects' Actions to avoid @ngrx/effects dependency - const actions$: ScannedActionsSubject = TestBed.inject(ScannedActionsSubject); + const actions$: ScannedActionsSubject = TestBed.get(ScannedActionsSubject); const log: any[] = []; router.events.subscribe(e => { if (e.hasOwnProperty('url')) { diff --git a/modules/router-store/spec/router_store_module.spec.ts b/modules/router-store/spec/router_store_module.spec.ts index 253e4d42c4..c61b275fc7 100644 --- a/modules/router-store/spec/router_store_module.spec.ts +++ b/modules/router-store/spec/router_store_module.spec.ts @@ -36,9 +36,9 @@ describe('Router Store Module', () => { }, }); - store = TestBed.inject(Store); - router = TestBed.inject(Router); - storeRouterConnectingModule = TestBed.inject(StoreRouterConnectingModule); + store = TestBed.get(Store); + router = TestBed.get(Router); + storeRouterConnectingModule = TestBed.get(StoreRouterConnectingModule); }); it('should have custom state key as own property', () => { @@ -95,9 +95,9 @@ describe('Router Store Module', () => { }, }); - store = TestBed.inject(Store); - router = TestBed.inject(Router); - storeRouterConnectingModule = TestBed.inject(StoreRouterConnectingModule); + store = TestBed.get(Store); + router = TestBed.get(Router); + storeRouterConnectingModule = TestBed.get(StoreRouterConnectingModule); }); it('should have same state selector as own property', () => { @@ -145,11 +145,9 @@ describe('Router Store Module', () => { }); return { - actions: TestBed.inject(ActionsSubject) as ActionsSubject, - router: TestBed.inject(Router) as Router, - serializer: TestBed.inject( - RouterStateSerializer - ) as RouterStateSerializer, + actions: TestBed.get(ActionsSubject) as ActionsSubject, + router: TestBed.get(Router) as Router, + serializer: TestBed.get(RouterStateSerializer) as RouterStateSerializer, }; } diff --git a/modules/schematics/src/container/files/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template b/modules/schematics/src/container/files/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template index 91de9a35b7..6c83a9b10c 100644 --- a/modules/schematics/src/container/files/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template +++ b/modules/schematics/src/container/files/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template @@ -20,7 +20,7 @@ describe('<%= classify(name) %>Component', () => { beforeEach(() => { fixture = TestBed.createComponent(<%= classify(name) %>Component); component = fixture.componentInstance; - store = TestBed.inject(Store); + store = TestBed.get(Store); fixture.detectChanges(); }); diff --git a/modules/schematics/src/container/index.spec.ts b/modules/schematics/src/container/index.spec.ts index d9289233ef..b477bb6b3d 100644 --- a/modules/schematics/src/container/index.spec.ts +++ b/modules/schematics/src/container/index.spec.ts @@ -141,7 +141,7 @@ describe('Container Schematic', () => { const content = tree.readContent( `${projectPath}/src/app/foo/foo.component.spec.ts` ); - expect(content).toMatch(/store = TestBed\.inject\(Store\);/); + expect(content).toMatch(/store = TestBed\.get\(Store\);/); }); it('should use StoreModule if integration test', async () => { diff --git a/modules/schematics/src/container/integration-files/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template b/modules/schematics/src/container/integration-files/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template index a4d5bdf1c2..f447cef647 100644 --- a/modules/schematics/src/container/integration-files/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template +++ b/modules/schematics/src/container/integration-files/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template @@ -20,7 +20,7 @@ describe('<%= classify(name) %>Component', () => { beforeEach(() => { fixture = TestBed.createComponent(<%= classify(name) %>Component); component = fixture.componentInstance; - store = TestBed.inject(Store); + store = TestBed.get(Store); spyOn(store, 'dispatch').and.callThrough(); fixture.detectChanges(); diff --git a/modules/schematics/src/data/files/__name@dasherize@if-flat__/__name@dasherize__.service.spec.ts.template b/modules/schematics/src/data/files/__name@dasherize@if-flat__/__name@dasherize__.service.spec.ts.template index 58a04a54e5..1f6a8fb58a 100644 --- a/modules/schematics/src/data/files/__name@dasherize@if-flat__/__name@dasherize__.service.spec.ts.template +++ b/modules/schematics/src/data/files/__name@dasherize@if-flat__/__name@dasherize__.service.spec.ts.template @@ -19,7 +19,7 @@ describe('<%= classify(name) %>Service', () => { }); beforeEach(() => { - service = TestBed.inject(<%= classify(name) %>Service) + service = TestBed.get(<%= classify(name) %>Service) }); it('should create an instance', () => { diff --git a/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.spec.ts.template b/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.spec.ts.template index ac458b149b..64ac0f0610 100644 --- a/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.spec.ts.template +++ b/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.spec.ts.template @@ -16,7 +16,7 @@ describe('<%= classify(name) %>Effects', () => { ] }); - effects = TestBed.inject<<%= classify(name) %>Effects>(<%= classify(name) %>Effects); + effects = TestBed.get<<%= classify(name) %>Effects>(<%= classify(name) %>Effects); }); it('should be created', () => { diff --git a/modules/schematics/src/effect/index.spec.ts b/modules/schematics/src/effect/index.spec.ts index 92a8a81c35..87b083adce 100644 --- a/modules/schematics/src/effect/index.spec.ts +++ b/modules/schematics/src/effect/index.spec.ts @@ -414,7 +414,7 @@ describe('Effect Schematic', () => { ); expect(content).toMatch( - /effects = TestBed\.inject\(FooEffects\);/ + /effects = TestBed\.get\(FooEffects\);/ ); }); }); diff --git a/modules/store-devtools/spec/integration.spec.ts b/modules/store-devtools/spec/integration.spec.ts index eb237e74ca..75500bd65b 100644 --- a/modules/store-devtools/spec/integration.spec.ts +++ b/modules/store-devtools/spec/integration.spec.ts @@ -29,13 +29,13 @@ describe('Devtools Integration', () => { imports: [RootModule], }); - const store = TestBed.inject(Store) as Store; - const devtools = TestBed.inject(StoreDevtools) as StoreDevtools; + const store = TestBed.get(Store) as Store; + const devtools = TestBed.get(StoreDevtools) as StoreDevtools; return { store, devtools }; } afterEach(() => { - const devtools = TestBed.inject(StoreDevtools) as StoreDevtools; + const devtools = TestBed.get(StoreDevtools) as StoreDevtools; devtools.reset(); }); diff --git a/modules/store-devtools/spec/store.spec.ts b/modules/store-devtools/spec/store.spec.ts index 3b9baee302..530214f537 100644 --- a/modules/store-devtools/spec/store.spec.ts +++ b/modules/store-devtools/spec/store.spec.ts @@ -92,10 +92,10 @@ function createStore( }); const testbed: TestBed = getTestBed(); - const store: Store = testbed.inject(Store); - const devtools: StoreDevtools = testbed.inject(StoreDevtools); - const state: StateObservable = testbed.inject(StateObservable); - const reducerManager: ReducerManager = testbed.inject(ReducerManager); + const store: Store = testbed.get(Store); + const devtools: StoreDevtools = testbed.get(StoreDevtools); + const state: StateObservable = testbed.get(StateObservable); + const reducerManager: ReducerManager = testbed.get(ReducerManager); let liftedValue: LiftedState; let value: any; diff --git a/modules/store/spec/edge.spec.ts b/modules/store/spec/edge.spec.ts index aae2d4c7da..0eda23d4d0 100644 --- a/modules/store/spec/edge.spec.ts +++ b/modules/store/spec/edge.spec.ts @@ -27,7 +27,7 @@ describe('ngRx Store', () => { ], }); - store = TestBed.inject(Store); + store = TestBed.get(Store); }); it('should provide an Observable Store', () => { diff --git a/modules/store/spec/integration.spec.ts b/modules/store/spec/integration.spec.ts index c953911a8b..3733a2f40c 100644 --- a/modules/store/spec/integration.spec.ts +++ b/modules/store/spec/integration.spec.ts @@ -62,8 +62,8 @@ describe('ngRx Integration spec', () => { imports: [StoreModule.forRoot(reducers, { initialState })], }); - store = TestBed.inject(Store); - state = TestBed.inject(State); + store = TestBed.get(Store); + state = TestBed.get(State); }); it('should successfully instantiate', () => { @@ -72,7 +72,7 @@ describe('ngRx Integration spec', () => { it('should combine reducers automatically if a key/value map is provided', () => { const action = { type: 'Test Action' }; - const reducer$: ReducerManager = TestBed.inject(ReducerManager); + const reducer$: ReducerManager = TestBed.get(ReducerManager); reducer$.pipe(first()).subscribe((reducer: ActionReducer) => { expect(reducer).toBeDefined(); @@ -85,7 +85,7 @@ describe('ngRx Integration spec', () => { }); it('should use a provided initial state', () => { - const resolvedInitialState = TestBed.inject(INITIAL_STATE); + const resolvedInitialState = TestBed.get(INITIAL_STATE); expect(resolvedInitialState).toEqual(initialState); }); @@ -409,7 +409,7 @@ describe('ngRx Integration spec', () => { ], }); - const store: Store = TestBed.inject(Store); + const store: Store = TestBed.get(Store); let expected = [ { @@ -444,7 +444,7 @@ describe('ngRx Integration spec', () => { ], }); - const store: Store = TestBed.inject(Store); + const store: Store = TestBed.get(Store); const expected = { todos: { @@ -469,8 +469,8 @@ describe('ngRx Integration spec', () => { imports: [StoreModule.forRoot({}), RouterTestingModule.withRoutes([])], }); - let router: Router = TestBed.inject(Router); - const loader: SpyNgModuleFactoryLoader = TestBed.inject( + let router: Router = TestBed.get(Router); + const loader: SpyNgModuleFactoryLoader = TestBed.get( NgModuleFactoryLoader ); diff --git a/modules/store/spec/modules.spec.ts b/modules/store/spec/modules.spec.ts index 914f831954..c874de1a02 100644 --- a/modules/store/spec/modules.spec.ts +++ b/modules/store/spec/modules.spec.ts @@ -91,7 +91,7 @@ describe(`Store Modules`, () => { imports: [RootModule], }); - store = TestBed.inject(Store); + store = TestBed.get(Store); }); it(`should accept configurations`, () => { @@ -132,7 +132,7 @@ describe(`Store Modules`, () => { ], }); - store = TestBed.inject(Store); + store = TestBed.get(Store); }); it('should have initial state', () => { @@ -196,7 +196,7 @@ describe(`Store Modules`, () => { imports: [RootModule], }); - store = TestBed.inject(Store); + store = TestBed.get(Store); }); it('should nest the child module in the root store object', () => { diff --git a/modules/store/spec/runtime_checks.spec.ts b/modules/store/spec/runtime_checks.spec.ts index e6171a0713..b94ef3cef2 100644 --- a/modules/store/spec/runtime_checks.spec.ts +++ b/modules/store/spec/runtime_checks.spec.ts @@ -79,7 +79,7 @@ describe('Runtime checks:', () => { ], }); - const _store = TestBed.inject>(Store); + const _store = TestBed.get>(Store); expect(serializationCheckMetaReducerSpy).toHaveBeenCalled(); }); @@ -101,7 +101,7 @@ describe('Runtime checks:', () => { ], }); - const _store = TestBed.inject>(Store); + const _store = TestBed.get>(Store); expect(serializationCheckMetaReducerSpy).not.toHaveBeenCalled(); }); @@ -125,7 +125,7 @@ describe('Runtime checks:', () => { ], }); - const _store = TestBed.inject>(Store); + const _store = TestBed.get>(Store); expect(serializationCheckMetaReducerSpy).not.toHaveBeenCalled(); expect(immutabilityCheckMetaReducerSpy).toHaveBeenCalled(); }); @@ -166,7 +166,7 @@ describe('Runtime checks:', () => { ], }); - const store: Store = TestBed.inject(Store); + const store: Store = TestBed.get(Store); const expected = ['internal-single-one', 'internal-single-two', 'user']; expect(logs).toEqual(expected); @@ -286,7 +286,7 @@ function setupStore(runtimeChecks?: Partial): Store { ], }); - return TestBed.inject(Store); + return TestBed.get(Store); } enum ErrorTypes { diff --git a/modules/store/spec/state.spec.ts b/modules/store/spec/state.spec.ts index 5990a4dc6d..e04c488f99 100644 --- a/modules/store/spec/state.spec.ts +++ b/modules/store/spec/state.spec.ts @@ -15,7 +15,7 @@ describe('ngRx State', () => { ], }); - TestBed.inject(Store); + TestBed.get(Store); expect(reducer).toHaveBeenCalledWith(initialState, { type: INIT, @@ -35,7 +35,7 @@ describe('ngRx State', () => { imports: [StoreModule.forRoot({ reducer })], }); - const store = TestBed.inject(Store) as Store; + const store = TestBed.get(Store) as Store; expect(() => { store.dispatch({ type: 'THROW_ERROR' }); flush(); diff --git a/modules/store/spec/store.spec.ts b/modules/store/spec/store.spec.ts index e7b79a53f2..4acdb3a4c5 100644 --- a/modules/store/spec/store.spec.ts +++ b/modules/store/spec/store.spec.ts @@ -49,8 +49,8 @@ describe('ngRx Store', () => { imports: [StoreModule.forRoot(reducers, { initialState, metaReducers })], }); - store = TestBed.inject(Store); - dispatcher = TestBed.inject(ActionsSubject); + store = TestBed.get(Store); + dispatcher = TestBed.get(ActionsSubject); } describe('initial state', () => { @@ -135,8 +135,8 @@ describe('ngRx Store', () => { }); function testInitialState(feature?: string) { - store = TestBed.inject(Store); - dispatcher = TestBed.inject(ActionsSubject); + store = TestBed.get(Store); + dispatcher = TestBed.get(ActionsSubject); const actionSequence = '--a--b--c--d--e--f--g'; const stateSequence = 'i-w-----x-----y--z---'; @@ -164,7 +164,7 @@ describe('ngRx Store', () => { } function testStoreValue(expected: any, done: DoneFn) { - store = TestBed.inject(Store); + store = TestBed.get(Store); store.pipe(take(1)).subscribe({ next(val) { @@ -308,8 +308,8 @@ describe('ngRx Store', () => { beforeEach(() => { setup(); - const reducerManager = TestBed.inject(ReducerManager); - const dispatcher = TestBed.inject(ReducerManagerDispatcher); + const reducerManager = TestBed.get(ReducerManager); + const dispatcher = TestBed.get(ReducerManagerDispatcher); addReducerSpy = spyOn(reducerManager, 'addReducer').and.callThrough(); removeReducerSpy = spyOn( reducerManager, @@ -365,8 +365,8 @@ describe('ngRx Store', () => { imports: [StoreModule.forRoot({})], }); - reducerManager = TestBed.inject(ReducerManager); - const dispatcher = TestBed.inject(ReducerManagerDispatcher); + reducerManager = TestBed.get(ReducerManager); + const dispatcher = TestBed.get(ReducerManagerDispatcher); reducerManagerDispatcherSpy = spyOn(dispatcher, 'next').and.callThrough(); }); @@ -511,7 +511,7 @@ describe('ngRx Store', () => { ], }); - const mockStore = TestBed.inject(Store); + const mockStore = TestBed.get(Store); const action = { type: INCREMENT }; mockStore.dispatch(action); @@ -536,7 +536,7 @@ describe('ngRx Store', () => { ], }); - const mockStore = TestBed.inject(Store); + const mockStore = TestBed.get(Store); mockStore.pipe(take(1)).subscribe({ next(val: any) { @@ -578,7 +578,7 @@ describe('ngRx Store', () => { ], }); - const mockStore = TestBed.inject(Store); + const mockStore = TestBed.get(Store); mockStore.pipe(take(1)).subscribe({ next(val: any) { @@ -626,7 +626,7 @@ describe('ngRx Store', () => { ], }); - const mockStore = TestBed.inject(Store); + const mockStore = TestBed.get(Store); mockStore.pipe(take(1)).subscribe({ next(val: any) { @@ -694,7 +694,7 @@ describe('ngRx Store', () => { }, ], }); - const mockStore = TestBed.inject(Store); + const mockStore = TestBed.get(Store); const action = { type: INCREMENT }; mockStore.dispatch(action); diff --git a/modules/store/testing/src/mock_store.ts b/modules/store/testing/src/mock_store.ts index 771255f419..6d8bb614e2 100644 --- a/modules/store/testing/src/mock_store.ts +++ b/modules/store/testing/src/mock_store.ts @@ -18,7 +18,7 @@ import { MOCK_SELECTORS } from './tokens'; if (typeof afterEach === 'function') { afterEach(() => { try { - const store = TestBed.inject(Store) as MockStore; + const store = TestBed.get(Store) as MockStore; if (store && 'resetSelectors' in store) { store.resetSelectors(); } diff --git a/projects/example-app/src/app/auth/containers/login-page.component.spec.ts b/projects/example-app/src/app/auth/containers/login-page.component.spec.ts index a120ae79aa..a26aacc90d 100644 --- a/projects/example-app/src/app/auth/containers/login-page.component.spec.ts +++ b/projects/example-app/src/app/auth/containers/login-page.component.spec.ts @@ -29,7 +29,7 @@ describe('Login Page', () => { fixture = TestBed.createComponent(LoginPageComponent); instance = fixture.componentInstance; - store = TestBed.inject(Store); + store = TestBed.get(Store); spyOn(store, 'dispatch'); }); diff --git a/projects/example-app/src/app/auth/effects/auth.effects.spec.ts b/projects/example-app/src/app/auth/effects/auth.effects.spec.ts index 8bc26b1a4e..90954bb6b0 100644 --- a/projects/example-app/src/app/auth/effects/auth.effects.spec.ts +++ b/projects/example-app/src/app/auth/effects/auth.effects.spec.ts @@ -44,11 +44,11 @@ describe('AuthEffects', () => { ], }); - effects = TestBed.inject(AuthEffects); - authService = TestBed.inject(AuthService); - actions$ = TestBed.inject(Actions); - routerService = TestBed.inject(Router); - dialog = TestBed.inject(MatDialog); + effects = TestBed.get(AuthEffects); + authService = TestBed.get(AuthService); + actions$ = TestBed.get(Actions); + routerService = TestBed.get(Router); + dialog = TestBed.get(MatDialog); spyOn(routerService, 'navigate').and.callThrough(); }); diff --git a/projects/example-app/src/app/auth/services/auth-guard.service.spec.ts b/projects/example-app/src/app/auth/services/auth-guard.service.spec.ts index 95d3f2eadd..f29db8bf90 100644 --- a/projects/example-app/src/app/auth/services/auth-guard.service.spec.ts +++ b/projects/example-app/src/app/auth/services/auth-guard.service.spec.ts @@ -15,8 +15,8 @@ describe('Auth Guard', () => { providers: [AuthGuard, provideMockStore()], }); - store = TestBed.inject(Store); - guard = TestBed.inject(AuthGuard); + store = TestBed.get(Store); + guard = TestBed.get(AuthGuard); loggedIn = store.overrideSelector(fromAuth.selectLoggedIn, false); }); diff --git a/projects/example-app/src/app/books/containers/collection-page.component.spec.ts b/projects/example-app/src/app/books/containers/collection-page.component.spec.ts index 62ac854016..692c131c5b 100644 --- a/projects/example-app/src/app/books/containers/collection-page.component.spec.ts +++ b/projects/example-app/src/app/books/containers/collection-page.component.spec.ts @@ -42,7 +42,7 @@ describe('Collection Page', () => { fixture = TestBed.createComponent(CollectionPageComponent); instance = fixture.componentInstance; - store = TestBed.inject(Store); + store = TestBed.get(Store); spyOn(store, 'dispatch'); }); diff --git a/projects/example-app/src/app/books/containers/find-book-page.component.spec.ts b/projects/example-app/src/app/books/containers/find-book-page.component.spec.ts index ef51da5f1e..0b9e421c5d 100644 --- a/projects/example-app/src/app/books/containers/find-book-page.component.spec.ts +++ b/projects/example-app/src/app/books/containers/find-book-page.component.spec.ts @@ -55,7 +55,7 @@ describe('Find Book Page', () => { fixture = TestBed.createComponent(FindBookPageComponent); instance = fixture.componentInstance; - store = TestBed.inject(Store); + store = TestBed.get(Store); spyOn(store, 'dispatch'); }); diff --git a/projects/example-app/src/app/books/containers/selected-book-page.component.spec.ts b/projects/example-app/src/app/books/containers/selected-book-page.component.spec.ts index c8b6af7e42..04caa2694f 100644 --- a/projects/example-app/src/app/books/containers/selected-book-page.component.spec.ts +++ b/projects/example-app/src/app/books/containers/selected-book-page.component.spec.ts @@ -34,7 +34,7 @@ describe('Selected Book Page', () => { fixture = TestBed.createComponent(SelectedBookPageComponent); instance = fixture.componentInstance; - store = TestBed.inject(Store); + store = TestBed.get(Store); spyOn(store, 'dispatch'); }); diff --git a/projects/example-app/src/app/books/containers/view-book-page.component.spec.ts b/projects/example-app/src/app/books/containers/view-book-page.component.spec.ts index 51c3d6b86d..c12bee010f 100644 --- a/projects/example-app/src/app/books/containers/view-book-page.component.spec.ts +++ b/projects/example-app/src/app/books/containers/view-book-page.component.spec.ts @@ -41,8 +41,8 @@ describe('View Book Page', () => { }); fixture = TestBed.createComponent(ViewBookPageComponent); - store = TestBed.inject(Store); - route = TestBed.inject(ActivatedRoute); + store = TestBed.get(Store); + route = TestBed.get(ActivatedRoute); jest.spyOn(store, 'dispatch'); }); diff --git a/projects/example-app/src/app/books/effects/book.effects.spec.ts b/projects/example-app/src/app/books/effects/book.effects.spec.ts index c3d398ba1d..4228570b4b 100644 --- a/projects/example-app/src/app/books/effects/book.effects.spec.ts +++ b/projects/example-app/src/app/books/effects/book.effects.spec.ts @@ -30,9 +30,9 @@ describe('BookEffects', () => { ], }); - effects = TestBed.inject(BookEffects); - googleBooksService = TestBed.inject(GoogleBooksService); - actions$ = TestBed.inject(Actions); + effects = TestBed.get(BookEffects); + googleBooksService = TestBed.get(GoogleBooksService); + actions$ = TestBed.get(Actions); }); describe('search$', () => { diff --git a/projects/example-app/src/app/books/effects/collection.effects.spec.ts b/projects/example-app/src/app/books/effects/collection.effects.spec.ts index 28d37f22f3..31138fe38e 100644 --- a/projects/example-app/src/app/books/effects/collection.effects.spec.ts +++ b/projects/example-app/src/app/books/effects/collection.effects.spec.ts @@ -50,9 +50,9 @@ describe('CollectionEffects', () => { ], }); - db = TestBed.inject(BookStorageService); - effects = TestBed.inject(CollectionEffects); - actions$ = TestBed.inject(Actions); + db = TestBed.get(BookStorageService); + effects = TestBed.get(CollectionEffects); + actions$ = TestBed.get(Actions); }); describe('checkStorageSupport$', () => { it('should call db.checkStorageSupport when initially subscribed to', () => { diff --git a/projects/example-app/src/app/core/effects/router.effects.spec.ts b/projects/example-app/src/app/core/effects/router.effects.spec.ts index b5a918be49..015e3bcc9f 100644 --- a/projects/example-app/src/app/core/effects/router.effects.spec.ts +++ b/projects/example-app/src/app/core/effects/router.effects.spec.ts @@ -26,8 +26,8 @@ describe('RouterEffects', () => { ], }); - effects = TestBed.inject(RouterEffects); - titleService = TestBed.inject(Title); + effects = TestBed.get(RouterEffects); + titleService = TestBed.get(Title); }); describe('updateTitle$', () => { diff --git a/projects/example-app/src/app/core/effects/user.effects.spec.ts b/projects/example-app/src/app/core/effects/user.effects.spec.ts index d19c304be6..aee801c3d0 100644 --- a/projects/example-app/src/app/core/effects/user.effects.spec.ts +++ b/projects/example-app/src/app/core/effects/user.effects.spec.ts @@ -19,7 +19,7 @@ describe('UserEffects', () => { providers: [UserEffects], }); - effects = TestBed.inject(UserEffects); + effects = TestBed.get(UserEffects); }); describe('idle$', () => { diff --git a/projects/example-app/src/app/core/services/book-storage.service.spec.ts b/projects/example-app/src/app/core/services/book-storage.service.spec.ts index 217f7021b8..fb17bf0b1b 100644 --- a/projects/example-app/src/app/core/services/book-storage.service.spec.ts +++ b/projects/example-app/src/app/core/services/book-storage.service.spec.ts @@ -34,7 +34,7 @@ describe('BookStorageService', () => { }, ], }); - fixture = TestBed.inject(BookStorageService); + fixture = TestBed.get(BookStorageService); }); describe('supported', () => { @@ -53,7 +53,7 @@ describe('BookStorageService', () => { ], }); - fixture = TestBed.inject(BookStorageService); + fixture = TestBed.get(BookStorageService); const expected = cold('#', {}, 'Local Storage Not Supported'); expect(fixture.supported()).toBeObservable(expected); }); diff --git a/projects/example-app/src/app/core/services/google-books.service.spec.ts b/projects/example-app/src/app/core/services/google-books.service.spec.ts index da252dc05c..9070d6f0ef 100644 --- a/projects/example-app/src/app/core/services/google-books.service.spec.ts +++ b/projects/example-app/src/app/core/services/google-books.service.spec.ts @@ -14,8 +14,8 @@ describe('Service: GoogleBooks', () => { providers: [{ provide: HttpClient, useValue: { get: jest.fn() } }], }); - service = TestBed.inject(GoogleBooksService); - http = TestBed.inject(HttpClient); + service = TestBed.get(GoogleBooksService); + http = TestBed.get(HttpClient); }); const data = {