|
| 1 | +import { Tree } from '@angular-devkit/schematics'; |
| 2 | +import { |
| 3 | + SchematicTestRunner, |
| 4 | + UnitTestTree, |
| 5 | +} from '@angular-devkit/schematics/testing'; |
| 6 | +import * as path from 'path'; |
| 7 | + |
| 8 | +describe('Store Migration 13_0_0 beta', () => { |
| 9 | + const collectionPath = path.join(__dirname, '../migration.json'); |
| 10 | + const pkgName = 'store'; |
| 11 | + |
| 12 | + it(`should replace createFeatureSelector usages with 2 generics`, async () => { |
| 13 | + const contents = ` |
| 14 | +import {createFeatureSelector} from '@ngrx/store' |
| 15 | +
|
| 16 | +// untouched |
| 17 | +const featureSelector1 = createFeatureSelector('feature1'); |
| 18 | +const featureSelector2 = createFeatureSelector<Feature>(feature2); |
| 19 | +const featureSelector3 = createFeatureSelector<State,Feature,SomethingElse>(feature3); |
| 20 | +const featureSelector4 = createFeatureSelector<fromFeat.State>('feature4'); |
| 21 | +
|
| 22 | +// modified |
| 23 | +const featureSelector5 = createFeatureSelector<State, Feature>('feature5'); |
| 24 | +const featureSelector6 = createFeatureSelector<State,Feature>(feature6); |
| 25 | +const featureSelector7 = createFeatureSelector<fromRoot.State, fromFeat.State>('feature7'); |
| 26 | +`; |
| 27 | + |
| 28 | + const expected = ` |
| 29 | +import {createFeatureSelector} from '@ngrx/store' |
| 30 | +
|
| 31 | +// untouched |
| 32 | +const featureSelector1 = createFeatureSelector('feature1'); |
| 33 | +const featureSelector2 = createFeatureSelector<Feature>(feature2); |
| 34 | +const featureSelector3 = createFeatureSelector<State,Feature,SomethingElse>(feature3); |
| 35 | +const featureSelector4 = createFeatureSelector<fromFeat.State>('feature4'); |
| 36 | +
|
| 37 | +// modified |
| 38 | +const featureSelector5 = createFeatureSelector< Feature>('feature5'); |
| 39 | +const featureSelector6 = createFeatureSelector<Feature>(feature6); |
| 40 | +const featureSelector7 = createFeatureSelector< fromFeat.State>('feature7'); |
| 41 | +`; |
| 42 | + |
| 43 | + const appTree = new UnitTestTree(Tree.empty()); |
| 44 | + appTree.create('./fixture.ts', contents); |
| 45 | + const runner = new SchematicTestRunner('schematics', collectionPath); |
| 46 | + |
| 47 | + const newTree = await runner |
| 48 | + .runSchematicAsync(`ngrx-${pkgName}-migration-13-beta`, {}, appTree) |
| 49 | + .toPromise(); |
| 50 | + const file = newTree.readContent('fixture.ts'); |
| 51 | + |
| 52 | + expect(file).toBe(expected); |
| 53 | + }); |
| 54 | +}); |
0 commit comments