Skip to content

Commit 3b9b890

Browse files
EnricoVogtbrandonroberts
authored andcommitted
fix(schematics): check for empty name when using store schematic for feature states (#1659) (#1666)
Closes #1659
1 parent 8dcd696 commit 3b9b890

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

modules/schematics/src/store/index.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,27 @@ describe('Store Schematic', () => {
215215
);
216216
expect(content).toMatch(/export interface FeatureState {/);
217217
});
218+
219+
it('should fail if a feature state name is not specified', () => {
220+
const options = {
221+
...defaultOptions,
222+
name: undefined,
223+
root: false,
224+
};
225+
226+
expect(() => {
227+
schematicRunner.runSchematic('store', options, appTree);
228+
}).toThrowError('Please provide a name for the feature state');
229+
});
230+
231+
it('should pass if a root state name is not specified', () => {
232+
const options = {
233+
...defaultOptions,
234+
name: undefined,
235+
};
236+
237+
expect(() => {
238+
schematicRunner.runSchematic('store', options, appTree);
239+
}).not.toThrow();
240+
});
218241
});

modules/schematics/src/store/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,13 @@ function addImportToNgModule(options: StoreOptions): Rule {
131131

132132
export default function(options: StoreOptions): Rule {
133133
return (host: Tree, context: SchematicContext) => {
134+
if (!options.name && !options.root) {
135+
throw new Error(`Please provide a name for the feature state`);
136+
}
137+
134138
options.path = getProjectPath(host, options);
135139

136-
const parsedPath = parseName(options.path, options.name);
140+
const parsedPath = parseName(options.path, options.name || '');
137141
options.name = parsedPath.name;
138142
options.path = parsedPath.path;
139143

0 commit comments

Comments
 (0)