|
| 1 | +import { |
| 2 | + SchematicTestRunner, |
| 3 | + UnitTestTree, |
| 4 | +} from '@angular-devkit/schematics/testing'; |
| 5 | +import * as path from 'path'; |
| 6 | +import { Schema as EntityOptions } from './schema'; |
| 7 | +import { createWorkspace } from '../../../schematics-core/testing'; |
| 8 | + |
| 9 | +describe('Entity ng-add Schematic', () => { |
| 10 | + const schematicRunner = new SchematicTestRunner( |
| 11 | + '@ngrx/entity', |
| 12 | + path.join(__dirname, '../collection.json') |
| 13 | + ); |
| 14 | + const defaultOptions: EntityOptions = { |
| 15 | + skipPackageJson: false, |
| 16 | + }; |
| 17 | + |
| 18 | + let appTree: UnitTestTree; |
| 19 | + |
| 20 | + beforeEach(() => { |
| 21 | + appTree = createWorkspace(schematicRunner, appTree); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should update package.json', () => { |
| 25 | + const options = { ...defaultOptions }; |
| 26 | + |
| 27 | + const tree = schematicRunner.runSchematic('ng-add', options, appTree); |
| 28 | + const packageJson = JSON.parse(tree.readContent('/package.json')); |
| 29 | + |
| 30 | + expect(packageJson.dependencies['@ngrx/entity']).toBeDefined(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should skip package.json update', () => { |
| 34 | + const options = { ...defaultOptions, skipPackageJson: true }; |
| 35 | + |
| 36 | + const tree = schematicRunner.runSchematic('ng-add', options, appTree); |
| 37 | + const packageJson = JSON.parse(tree.readContent('/package.json')); |
| 38 | + |
| 39 | + expect(packageJson.dependencies['@ngrx/entity']).toBeUndefined(); |
| 40 | + }); |
| 41 | +}); |
0 commit comments