diff --git a/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template b/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template index 1ce9bc7bc745..070ef601b634 100644 --- a/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template +++ b/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { <%= classify(name) %><%= classify(type) %> } from './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>'; +import <% if(!exportDefault) { %>{ <% }%><%= classify(name) %><%= classify(type) %> <% if(!exportDefault) {%>} <% }%>from './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>'; describe('<%= classify(name) %><%= classify(type) %>', () => { let component: <%= classify(name) %><%= classify(type) %>; diff --git a/packages/schematics/angular/component/index_spec.ts b/packages/schematics/angular/component/index_spec.ts index 16352ac96482..7cfa8461d4f0 100644 --- a/packages/schematics/angular/component/index_spec.ts +++ b/packages/schematics/angular/component/index_spec.ts @@ -511,6 +511,9 @@ describe('Component Schematic', () => { const tree = await schematicRunner.runSchematic('component', options, appTree); const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts'); expect(tsContent).toContain('export default class FooComponent'); + + const specContent = tree.readContent('/projects/bar/src/app/foo/foo.component.spec.ts'); + expect(specContent).toContain("import FooComponent from './foo.component';"); }); it('should export the component as a named export when exportDefault is false', async () => { @@ -519,5 +522,8 @@ describe('Component Schematic', () => { const tree = await schematicRunner.runSchematic('component', options, appTree); const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts'); expect(tsContent).toContain('export class FooComponent'); + + const specContent = tree.readContent('/projects/bar/src/app/foo/foo.component.spec.ts'); + expect(specContent).toContain("import { FooComponent } from './foo.component';"); }); });