Skip to content

Commit

Permalink
fix(schematics): avoid lastIndexOf error while creating store schemat…
Browse files Browse the repository at this point in the history
…ics (ngrx#1659)
  • Loading branch information
EnricoVogt committed Mar 31, 2019
1 parent 78e237c commit 1f251ad
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 27 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,31 @@ 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,
};

let thrownError: Error | null = null;
try {
schematicRunner.runSchematic('store', options, appTree);
} catch (err) {
thrownError = err;
}
expect(thrownError).toBeDefined();
});

it('should pass if a root state name is not specified', () => {
const options = {
...defaultOptions,
name: undefined,
};

expect(function() {
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 1f251ad

Please sign in to comment.