Skip to content

Commit 4a59335

Browse files
thekhegayalan-agius4
authored andcommitted
fix(@schematics/angular): include the type separator in the class spec import
class spec template imports `'./<name><type>'`, and `type` reaches it without leading dot since class schematic moved to `generateFromFiles` so `ng g class user --type=model` writes `user.model.spec.ts` with `import { User } from './usermodel'` and generated spec does not compile template now adds dot only when type is set, matching `__type__` file name token
1 parent 9534f62 commit 4a59335

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎packages/schematics/angular/class/files/__name@dasherize__.__type__.spec.ts.template‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { <%= classify(name) %> } from './<%= dasherize(name) %><%= type %>';
1+
import { <%= classify(name) %> } from './<%= dasherize(name) %><%= type ? '.' + type : '' %>';
22

33
describe('<%= classify(name) %>', () => {
44
it('should create an instance', () => {

‎packages/schematics/angular/class/index_spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ describe('Class Schematic', () => {
7474
expect(tree.files).toContain('/projects/bar/src/app/foo.model.ts');
7575
});
7676

77+
it('should import the class from the typed file in the spec file', async () => {
78+
const options = { ...defaultOptions, type: 'model', skipTests: false };
79+
80+
const tree = await schematicRunner.runSchematic('class', options, appTree);
81+
const specContent = tree.readContent('/projects/bar/src/app/foo.model.spec.ts');
82+
expect(specContent).toContain("import { Foo } from './foo.model';");
83+
});
84+
7785
it('should split the name to name & type with split on "."', async () => {
7886
const options = { ...defaultOptions, name: 'foo.model' };
7987
const tree = await schematicRunner.runSchematic('class', options, appTree);

0 commit comments

Comments
 (0)