Skip to content

Commit

Permalink
repro: nested if/for control flow migration error
Browse files Browse the repository at this point in the history
  • Loading branch information
cexbrayat committed Oct 19, 2023
1 parent 8fff07c commit 2991e16
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/core/schematics/test/control_flow_migration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,43 @@ describe('control flow migration', () => {
].join('\n'));
});

it('should migrate an inline template with if and for loops nested', async () => {
writeFile('/comp.ts', `
import {Component} from '@angular/core';
import {NgIf, NgFor} from '@angular/common';
@Component({
imports: [NgFor, NgIf],
templateUrl: './comp.html'
})
export class UserComponent {
countries = ['Belgium', 'France'];
cities = ['Paris', 'Lyon'];
}
`);

writeFile('/comp.html', [
`<ul>`,
`<li *ngFor="let country of countries">{{ country }}</li>`,
`</ul>`,
`<ul *ngIf="true">`,
`<li *ngFor="let city of cities">{{ city }}</li>`,
`</ul>`,
].join('\n'));

await runMigration();
const content = tree.readContent('/comp.html');

expect(content).toBe([
`<ul>`,
`@for (country of countries; track country) {<li>{{ country }}</li>}`,
`</ul>`,
`@if (true) {<ul>`,
`@for (city of cities; track city) {<li>{{ city }}</li>}`,
`</ul>}`,
].join('\n'));
});

it('should migrate an inline template with if, else and for loops', async () => {
writeFile('/comp.ts', `
import {Component} from '@angular/core';
Expand Down

0 comments on commit 2991e16

Please sign in to comment.