Skip to content

Commit

Permalink
fix(schematics): check for empty name when using store schematic for …
Browse files Browse the repository at this point in the history
…feature states (#1659) (#1666)

Closes #1659
  • Loading branch information
EnricoVogt authored and brandonroberts committed Apr 3, 2019
1 parent 8dcd696 commit 3b9b890
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 23 additions & 0 deletions modules/schematics/src/store/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
6 changes: 5 additions & 1 deletion modules/schematics/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3b9b890

Please sign in to comment.