Skip to content

Commit

Permalink
fix(@schematics/angular): component spec with export default
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
cexbrayat authored and clydin committed Nov 1, 2024
1 parent 296ea8f commit b1504c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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) %>;
Expand Down
6 changes: 6 additions & 0 deletions packages/schematics/angular/component/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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';");
});
});

0 comments on commit b1504c3

Please sign in to comment.