Skip to content

Commit

Permalink
fixup! fix(router): fix angular#49457 outlet activating with old info
Browse files Browse the repository at this point in the history
  • Loading branch information
jancabadaj committed Mar 17, 2023
1 parent 8225c9e commit 19bbbe1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/router/test/directives/router_outlet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,47 @@ describe('router outlet name', () => {
advance(fixture);
expect(fixture.nativeElement.innerHTML).toMatch('.*component 3.*component 2.*component 1');
}));

it('should not activate if route is changed', fakeAsync(() => {
@Component({
standalone: true,
template: '<div *ngIf="initDone"><router-outlet></router-outlet></div>',
imports: [RouterOutlet, CommonModule],
})
class ParentCmp {
initDone = false;
constructor() {
setTimeout(() => this.initDone = true, 1000);
}
}

@Component({
template: 'child component',
standalone: true,
})
class ChildCmp {
}

TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes([
{path: 'parent', component: ParentCmp, children: [{path: 'child', component: ChildCmp}]}
])]
});
const router = TestBed.inject(Router);
const fixture = createRoot(router, ParentCmp);

advance(fixture, 250);
router.navigate(['parent/child']);
advance(fixture, 250);
// Not contain because initDone is still false
expect(fixture.nativeElement.innerHTML).not.toContain('child component');

advance(fixture, 1500);
router.navigate(['parent']);
advance(fixture, 1500);
// Not contain because route was changed back to parent
expect(fixture.nativeElement.innerHTML).not.toContain('child component');
}));
});

function advance(fixture: ComponentFixture<unknown>, millis?: number): void {
Expand Down

0 comments on commit 19bbbe1

Please sign in to comment.