Skip to content

Commit b1504c3

Browse files
cexbrayatclydin
authored andcommitted
fix(@schematics/angular): component spec with export default
The generated spec was using the same import when it should be adapted if `exportDefault` is used: ```ts import { UserComponent } from './user.component.ts` ``` It now produces: ```ts import UserComponent from './user.component.ts` ``` (cherry picked from commit 51fd980)
1 parent 296ea8f commit b1504c3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22

3-
import { <%= classify(name) %><%= classify(type) %> } from './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>';
3+
import <% if(!exportDefault) { %>{ <% }%><%= classify(name) %><%= classify(type) %> <% if(!exportDefault) {%>} <% }%>from './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>';
44

55
describe('<%= classify(name) %><%= classify(type) %>', () => {
66
let component: <%= classify(name) %><%= classify(type) %>;

packages/schematics/angular/component/index_spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ describe('Component Schematic', () => {
511511
const tree = await schematicRunner.runSchematic('component', options, appTree);
512512
const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
513513
expect(tsContent).toContain('export default class FooComponent');
514+
515+
const specContent = tree.readContent('/projects/bar/src/app/foo/foo.component.spec.ts');
516+
expect(specContent).toContain("import FooComponent from './foo.component';");
514517
});
515518

516519
it('should export the component as a named export when exportDefault is false', async () => {
@@ -519,5 +522,8 @@ describe('Component Schematic', () => {
519522
const tree = await schematicRunner.runSchematic('component', options, appTree);
520523
const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
521524
expect(tsContent).toContain('export class FooComponent');
525+
526+
const specContent = tree.readContent('/projects/bar/src/app/foo/foo.component.spec.ts');
527+
expect(specContent).toContain("import { FooComponent } from './foo.component';");
522528
});
523529
});

0 commit comments

Comments
 (0)