Skip to content

Commit

Permalink
test(component): update usage of TestBed.get to TestBed.inject
Browse files Browse the repository at this point in the history
angular 9 compatibillity changes for TestBed

Closes ngrx#2240

test(docs): test cases updated in docs

TestBed.get replaced by TestBed.inject

Closes #ngrx#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 ngrx#2240

test(docs): test cases updated in docs

TestBed.get replaced by TestBed.inject

Closes #ngrx#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
  • Loading branch information
sumitparakh committed Jan 10, 2020
1 parent e9d6189 commit 6adf6eb
Show file tree
Hide file tree
Showing 41 changed files with 132 additions and 136 deletions.
4 changes: 2 additions & 2 deletions docs/effects/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('My Effects', () => {
],
});

effects = TestBed.inject(MyEffects);
effects = TestBed.get(MyEffects);
});

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

effects = TestBed.inject(MyEffects);
effects = TestBed.get(MyEffects);
metadata = getEffectsMetadata(effects);
});

Expand Down
6 changes: 3 additions & 3 deletions modules/data/spec/effects/entity-cache-effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ describe('EntityCacheEffects (normal testing)', () => {
],
});

actions$ = TestBed.inject<any>(Actions);
effects = TestBed.inject(EntityCacheEffects);
dataService = TestBed.inject<any>(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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('EntityDefinitionService', () => {
{ provide: ENTITY_METADATA_TOKEN, multi: true, useValue: metadataMap },
],
});
service = TestBed.inject(EntityDefinitionService);
service = TestBed.get(EntityDefinitionService);
});

describe('#getDefinition', () => {
Expand Down
6 changes: 3 additions & 3 deletions modules/data/spec/selectors/related-entity-selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
4 changes: 2 additions & 2 deletions modules/data/spec/utils/default-pluralizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('DefaultPluralizer', () => {
],
});

pluralizer = TestBed.inject(Pluralizer);
pluralizer = TestBed.get(Pluralizer);
});

it('should pluralize "Villain" which is not in plural names', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/effects/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe('Effects ng-add Schematic', () => {
);

expect(content).toMatch(
/effects = TestBed\.inject<FooEffects>\(FooEffects\);/
/effects = TestBed\.get<FooEffects>\(FooEffects\);/
);
});
});
6 changes: 3 additions & 3 deletions modules/effects/spec/effect_sources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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',
});
Expand Down
8 changes: 4 additions & 4 deletions modules/effects/spec/effects_feature_module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ describe('Effects Feature Module', () => {
],
});

mockEffectSources = TestBed.inject<any>(EffectsRootModule);
mockEffectSources = TestBed.get<any>(EffectsRootModule);
});

it('should add all effects when instantiated', () => {
TestBed.inject(EffectsFeatureModule);
TestBed.get(EffectsFeatureModule);

expect(mockEffectSources.addEffects).toHaveBeenCalledWith(sourceA);
expect(mockEffectSources.addEffects).toHaveBeenCalledWith(sourceB);
Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions modules/effects/spec/effects_root_module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Effects Root Module', () => {
],
});

const store = TestBed.inject(Store);
const store = TestBed.get(Store);

expect(reducer).toHaveBeenCalledWith(foo, {
type: INIT,
Expand All @@ -37,7 +37,7 @@ describe('Effects Root Module', () => {
],
});

const store = TestBed.inject(Store);
const store = TestBed.get(Store);

expect(reducer).toHaveBeenCalledWith(foo, {
type: INIT,
Expand Down
10 changes: 4 additions & 6 deletions modules/effects/spec/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ describe('NgRx Effects Integration spec', () => {
],
});

const store = TestBed.inject(Store) as Store<any>;
const store = TestBed.get(Store) as Store<any>;

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'));
Expand Down Expand Up @@ -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<any>(
NgModuleFactoryLoader
);
let router: Router = TestBed.get(Router);
const loader: SpyNgModuleFactoryLoader = TestBed.get(NgModuleFactoryLoader);

loader.stubbedModules = { feature: FeatModuleWithForRoot };
router.resetConfig([{ path: 'feature-path', loadChildren: 'feature' }]);
Expand Down
48 changes: 24 additions & 24 deletions modules/router-store/spec/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<any>) =>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -271,8 +271,8 @@ describe('integration spec', () => {
config: { stateKey: 'reducer' },
});

const router: Router = TestBed.inject(Router);
const store: Store<any> = TestBed.inject(Store);
const router: Router = TestBed.get(Router);
const store: Store<any> = TestBed.get(Store);
const log = logOfRouterAndActionsAndStore();

router
Expand Down Expand Up @@ -330,7 +330,7 @@ describe('integration spec', () => {
},
});

const router: Router = TestBed.inject(Router);
const router: Router = TestBed.get(Router);
const log = logOfRouterAndActionsAndStore();

router
Expand Down Expand Up @@ -417,8 +417,8 @@ describe('integration spec', () => {
config: { stateKey: 'reducer' },
});

const router: Router = TestBed.inject(Router);
const store: Store<any> = TestBed.inject(Store);
const router: Router = TestBed.get(Router);
const store: Store<any> = TestBed.get(Store);
const log = logOfRouterAndActionsAndStore();

router
Expand Down Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -725,8 +725,8 @@ describe('integration spec', () => {
},
});

const router: Router = TestBed.inject(Router);
const store: Store<any> = TestBed.inject(Store);
const router: Router = TestBed.get(Router);
const store: Store<any> = TestBed.get(Store);
const log = logOfRouterAndActionsAndStore();

router
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -1002,10 +1002,10 @@ function logOfRouterAndActionsAndStore(
stateKey: 'reducer',
}
): any[] {
const router: Router = TestBed.inject(Router);
const store: Store<any> = TestBed.inject(Store);
const router: Router = TestBed.get(Router);
const store: Store<any> = 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')) {
Expand Down
20 changes: 9 additions & 11 deletions modules/router-store/spec/router_store_module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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,
};
}

Expand Down
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.inject<Store>(Store);
store = TestBed.get<Store>(Store);

fixture.detectChanges();
});
Expand Down
Loading

0 comments on commit 6adf6eb

Please sign in to comment.