diff --git a/modules/schematics/src/store/index.spec.ts b/modules/schematics/src/store/index.spec.ts index 741ae04756..9f0d63e469 100644 --- a/modules/schematics/src/store/index.spec.ts +++ b/modules/schematics/src/store/index.spec.ts @@ -215,4 +215,27 @@ describe('Store Schematic', () => { ); expect(content).toMatch(/export interface FeatureState {/); }); + + it('should fail if a feature state name is not specified', () => { + const options = { + ...defaultOptions, + name: undefined, + root: false, + }; + + expect(() => { + schematicRunner.runSchematic('store', options, appTree); + }).toThrowError('Please provide a name for the feature state'); + }); + + it('should pass if a root state name is not specified', () => { + const options = { + ...defaultOptions, + name: undefined, + }; + + expect(() => { + schematicRunner.runSchematic('store', options, appTree); + }).not.toThrow(); + }); }); diff --git a/modules/schematics/src/store/index.ts b/modules/schematics/src/store/index.ts index db06f31df2..51c67a4935 100644 --- a/modules/schematics/src/store/index.ts +++ b/modules/schematics/src/store/index.ts @@ -131,9 +131,13 @@ function addImportToNgModule(options: StoreOptions): Rule { export default function(options: StoreOptions): Rule { return (host: Tree, context: SchematicContext) => { + if (!options.name && !options.root) { + throw new Error(`Please provide a name for the feature state`); + } + options.path = getProjectPath(host, options); - const parsedPath = parseName(options.path, options.name); + const parsedPath = parseName(options.path, options.name || ''); options.name = parsedPath.name; options.path = parsedPath.path;