Skip to content

Commit d601f44

Browse files
committed
test: duplicate imports are removed
1 parent d45b1f0 commit d601f44

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

apps/angular/ionic-angular-standalone/src/app/view-child/view-child.page.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IonContent, IonicModule } from '@ionic/angular';
77
selector: 'app-view-child',
88
templateUrl: './view-child.page.html',
99
standalone: true,
10-
imports: [IonicModule, CommonModule, FormsModule]
10+
imports: [IonicModule, CommonModule, FormsModule],
1111
})
1212
export class ViewChildPage implements OnInit {
1313
/**
@@ -16,7 +16,7 @@ export class ViewChildPage implements OnInit {
1616
@ViewChild(IonContent)
1717
content!: IonContent;
1818

19-
constructor() { }
19+
constructor() {}
2020

21-
ngOnInit() { }
21+
ngOnInit() {}
2222
}

packages/cli/src/angular/migrations/standalone/0002-import-standalone-component.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,49 @@ describe("migrateComponents", () => {
167167
);
168168
});
169169

170+
it("should remove duplicate imports from existing declarations", async () => {
171+
const project = new Project({ useInMemoryFileSystem: true });
172+
173+
const component = `
174+
import { Component, ViewChild } from "@angular/core";
175+
import { IonContent, IonicModule } from "@ionic/angular";
176+
177+
@Component({
178+
selector: 'my-component',
179+
template: '<ion-content></ion-content>',
180+
standalone: true,
181+
imports: [IonicModule]
182+
})
183+
export class MyComponent {
184+
@ViewChild(IonContent) content!: IonContent;
185+
}
186+
`;
187+
188+
const componentSourceFile = project.createSourceFile(
189+
"foo.component.ts",
190+
dedent(component),
191+
);
192+
193+
await migrateComponents(project, { dryRun: false });
194+
195+
expect(dedent(componentSourceFile.getText())).toBe(
196+
dedent(`
197+
import { Component, ViewChild } from "@angular/core";
198+
import { IonContent } from "@ionic/angular/standalone";
199+
200+
@Component({
201+
selector: 'my-component',
202+
template: '<ion-content></ion-content>',
203+
standalone: true,
204+
imports: [IonContent]
205+
})
206+
export class MyComponent {
207+
@ViewChild(IonContent) content!: IonContent;
208+
}
209+
`),
210+
);
211+
});
212+
170213
describe("hyperlinks", () => {
171214
it("should detect and import routerLink used in the template", async () => {
172215
const project = new Project({ useInMemoryFileSystem: true });

0 commit comments

Comments
 (0)