Skip to content

Commit e5c2aed

Browse files
brandonrobertsMikeRyanDev
authored andcommitted
fix(Schematics): Don't add state import if not provided (#697)
1 parent dffb539 commit e5c2aed

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,18 @@ describe('Container Schematic', () => {
263263
/import { FooComponent } from '.\/foo\/foo.component/
264264
);
265265
});
266+
267+
it('should respect the state option if not provided', () => {
268+
const options = { ...defaultOptions, state: undefined };
269+
const tree = schematicRunner.runSchematic('container', options, appTree);
270+
const content = getFileContent(tree, '/src/app/foo/foo.component.ts');
271+
expect(content).not.toMatch(/import \* as fromStore/);
272+
});
273+
274+
it('should import the state path if provided', () => {
275+
const options = { ...defaultOptions, state: 'reducers' };
276+
const tree = schematicRunner.runSchematic('container', options, appTree);
277+
const content = getFileContent(tree, '/src/app/foo/foo.component.ts');
278+
expect(content).toMatch(/import \* as fromStore from '..\/reducers';/);
279+
});
266280
});

modules/schematics/src/container/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,18 @@ export default function(options: ContainerOptions): Rule {
123123
options.path = options.path ? normalize(options.path) : options.path;
124124
options.module = findModuleFromOptions(host, options);
125125

126-
const statePath = `/${options.sourceDir}/${options.path}/${options.state}`;
127126
const componentPath =
128127
`/${options.sourceDir}/${options.path}/` +
129128
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
130129
stringUtils.dasherize(options.name) +
131130
'.component';
132-
options.state = buildRelativePath(componentPath, statePath);
131+
132+
if (options.state) {
133+
const statePath = `/${options.sourceDir}/${options.path}/${
134+
options.state
135+
}`;
136+
options.state = buildRelativePath(componentPath, statePath);
137+
}
133138

134139
const templateSource = apply(url('./files'), [
135140
options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')),

0 commit comments

Comments
 (0)