test(ivy): add root causes for router TestBed failures (#28014)
PR Close #28014
This commit is contained in:
parent
29e3144269
commit
5609764886
|
@ -451,7 +451,7 @@ describe('Integration', () => {
|
|||
expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]');
|
||||
})));
|
||||
|
||||
fixmeIvy('unknown/maybe FW-918')
|
||||
fixmeIvy('FW-768: markViewDirty instruction is scheduling a tick')
|
||||
.it('should work when an outlet is in an ngIf',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
@ -468,40 +468,38 @@ describe('Integration', () => {
|
|||
expect(location.path()).toEqual('/child/simple');
|
||||
})));
|
||||
|
||||
it('should work when an outlet is added/removed', fakeAsync(() => {
|
||||
@Component({
|
||||
selector: 'someRoot',
|
||||
template: `[<div *ngIf="cond"><router-outlet></router-outlet></div>]`
|
||||
})
|
||||
class RootCmpWithLink {
|
||||
cond: boolean = true;
|
||||
}
|
||||
TestBed.configureTestingModule({declarations: [RootCmpWithLink]});
|
||||
fixmeIvy('FW-768: markViewDirty instruction is scheduling a tick')
|
||||
.it('should work when an outlet is added/removed', fakeAsync(() => {
|
||||
@Component({
|
||||
selector: 'someRoot',
|
||||
template: `[<div *ngIf="cond"><router-outlet></router-outlet></div>]`
|
||||
})
|
||||
class RootCmpWithLink {
|
||||
cond: boolean = true;
|
||||
}
|
||||
TestBed.configureTestingModule({declarations: [RootCmpWithLink]});
|
||||
|
||||
const router: Router = TestBed.get(Router);
|
||||
const router: Router = TestBed.get(Router);
|
||||
|
||||
const fixture = createRoot(router, RootCmpWithLink);
|
||||
const fixture = createRoot(router, RootCmpWithLink);
|
||||
|
||||
router.resetConfig([
|
||||
{path: 'simple', component: SimpleCmp},
|
||||
{path: 'blank', component: BlankCmp},
|
||||
]);
|
||||
router.resetConfig([
|
||||
{path: 'simple', component: SimpleCmp},
|
||||
{path: 'blank', component: BlankCmp},
|
||||
]);
|
||||
|
||||
router.navigateByUrl('/simple');
|
||||
advance(fixture);
|
||||
expect(fixture.nativeElement).toHaveText('[simple]');
|
||||
router.navigateByUrl('/simple');
|
||||
advance(fixture);
|
||||
expect(fixture.nativeElement).toHaveText('[simple]');
|
||||
|
||||
fixture.componentInstance.cond = false;
|
||||
advance(fixture);
|
||||
expect(fixture.nativeElement).toHaveText('[]');
|
||||
fixture.componentInstance.cond = false;
|
||||
advance(fixture);
|
||||
expect(fixture.nativeElement).toHaveText('[]');
|
||||
|
||||
fixture.componentInstance.cond = true;
|
||||
advance(fixture);
|
||||
expect(fixture.nativeElement).toHaveText('[simple]');
|
||||
|
||||
// TODO: remove extra tick for Ivy?
|
||||
tick();
|
||||
}));
|
||||
fixture.componentInstance.cond = true;
|
||||
advance(fixture);
|
||||
expect(fixture.nativeElement).toHaveText('[simple]');
|
||||
}));
|
||||
|
||||
it('should update location when navigating', fakeAsync(() => {
|
||||
@Component({template: `record`})
|
||||
|
@ -635,7 +633,7 @@ describe('Integration', () => {
|
|||
expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]');
|
||||
})));
|
||||
|
||||
fixmeIvy('unknown/maybe FW-918')
|
||||
fixmeIvy('FW-768: markViewDirty instruction is scheduling a tick')
|
||||
.it('should navigate back and forward',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
@ -1008,7 +1006,7 @@ describe('Integration', () => {
|
|||
]);
|
||||
})));
|
||||
|
||||
fixmeIvy('unknown/maybe FW-918')
|
||||
fixmeIvy('FW-768: markViewDirty instruction is scheduling a tick')
|
||||
.it('should handle failed navigations gracefully',
|
||||
fakeAsync(inject([Router], (router: Router) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
@ -2033,7 +2031,7 @@ describe('Integration', () => {
|
|||
});
|
||||
});
|
||||
|
||||
fixmeIvy('unknown/maybe FW-918')
|
||||
fixmeIvy('FW-768: markViewDirty instruction is scheduling a tick')
|
||||
.it('works',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
@ -2056,7 +2054,7 @@ describe('Integration', () => {
|
|||
|
||||
beforeEach(() => { TestBed.configureTestingModule({providers: [AlwaysTrue]}); });
|
||||
|
||||
fixmeIvy('unknown/maybe FW-918')
|
||||
fixmeIvy('FW-768: markViewDirty instruction is scheduling a tick')
|
||||
.it('works',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
@ -3357,7 +3355,7 @@ describe('Integration', () => {
|
|||
});
|
||||
|
||||
describe('route events', () => {
|
||||
fixmeIvy('unknown/maybe FW-918')
|
||||
fixmeIvy('FW-768: markViewDirty instruction is scheduling a tick')
|
||||
.it('should fire matching (Child)ActivationStart/End events',
|
||||
fakeAsync(inject([Router], (router: Router) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
@ -4530,84 +4528,82 @@ describe('Integration', () => {
|
|||
expect(simpleCmp1).not.toBe(simpleCmp2);
|
||||
})));
|
||||
|
||||
it('should not mount the component of the previously reused route when the outlet was not instantiated at the time of route activation',
|
||||
fakeAsync(() => {
|
||||
@Component({
|
||||
selector: 'root-cmp',
|
||||
template:
|
||||
'<div *ngIf="isToolpanelShowing"><router-outlet name="toolpanel"></router-outlet></div>'
|
||||
})
|
||||
class RootCmpWithCondOutlet implements OnDestroy {
|
||||
private subscription: Subscription;
|
||||
public isToolpanelShowing: boolean = false;
|
||||
fixmeIvy('FW-768: markViewDirty instruction is scheduling a tick')
|
||||
.it('should not mount the component of the previously reused route when the outlet was not instantiated at the time of route activation',
|
||||
fakeAsync(() => {
|
||||
@Component({
|
||||
selector: 'root-cmp',
|
||||
template:
|
||||
'<div *ngIf="isToolpanelShowing"><router-outlet name="toolpanel"></router-outlet></div>'
|
||||
})
|
||||
class RootCmpWithCondOutlet implements OnDestroy {
|
||||
private subscription: Subscription;
|
||||
public isToolpanelShowing: boolean = false;
|
||||
|
||||
constructor(router: Router) {
|
||||
this.subscription =
|
||||
router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(
|
||||
() => this.isToolpanelShowing =
|
||||
!!router.parseUrl(router.url).root.children['toolpanel']);
|
||||
}
|
||||
constructor(router: Router) {
|
||||
this.subscription =
|
||||
router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(
|
||||
() => this.isToolpanelShowing =
|
||||
!!router.parseUrl(router.url).root.children['toolpanel']);
|
||||
}
|
||||
|
||||
public ngOnDestroy(): void { this.subscription.unsubscribe(); }
|
||||
}
|
||||
public ngOnDestroy(): void { this.subscription.unsubscribe(); }
|
||||
}
|
||||
|
||||
@Component({selector: 'tool-1-cmp', template: 'Tool 1 showing'})
|
||||
class Tool1Component {
|
||||
}
|
||||
@Component({selector: 'tool-1-cmp', template: 'Tool 1 showing'})
|
||||
class Tool1Component {
|
||||
}
|
||||
|
||||
@Component({selector: 'tool-2-cmp', template: 'Tool 2 showing'})
|
||||
class Tool2Component {
|
||||
}
|
||||
@Component({selector: 'tool-2-cmp', template: 'Tool 2 showing'})
|
||||
class Tool2Component {
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [RootCmpWithCondOutlet, Tool1Component, Tool2Component],
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterTestingModule.withRoutes([
|
||||
{path: 'a', outlet: 'toolpanel', component: Tool1Component},
|
||||
{path: 'b', outlet: 'toolpanel', component: Tool2Component},
|
||||
]),
|
||||
],
|
||||
})
|
||||
class TestModule {
|
||||
}
|
||||
@NgModule({
|
||||
declarations: [RootCmpWithCondOutlet, Tool1Component, Tool2Component],
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterTestingModule.withRoutes([
|
||||
{path: 'a', outlet: 'toolpanel', component: Tool1Component},
|
||||
{path: 'b', outlet: 'toolpanel', component: Tool2Component},
|
||||
]),
|
||||
],
|
||||
})
|
||||
class TestModule {
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({imports: [TestModule]});
|
||||
TestBed.configureTestingModule({imports: [TestModule]});
|
||||
|
||||
const router: Router = TestBed.get(Router);
|
||||
router.routeReuseStrategy = new AttachDetachReuseStrategy();
|
||||
const router: Router = TestBed.get(Router);
|
||||
router.routeReuseStrategy = new AttachDetachReuseStrategy();
|
||||
|
||||
const fixture = createRoot(router, RootCmpWithCondOutlet);
|
||||
const fixture = createRoot(router, RootCmpWithCondOutlet);
|
||||
|
||||
// Activate 'tool-1'
|
||||
router.navigate([{outlets: {toolpanel: 'a'}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).toContainComponent(Tool1Component, '(a)');
|
||||
// Activate 'tool-1'
|
||||
router.navigate([{outlets: {toolpanel: 'a'}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).toContainComponent(Tool1Component, '(a)');
|
||||
|
||||
// Deactivate 'tool-1'
|
||||
router.navigate([{outlets: {toolpanel: null}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).not.toContainComponent(Tool1Component, '(b)');
|
||||
// Deactivate 'tool-1'
|
||||
router.navigate([{outlets: {toolpanel: null}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).not.toContainComponent(Tool1Component, '(b)');
|
||||
|
||||
// Activate 'tool-1'
|
||||
router.navigate([{outlets: {toolpanel: 'a'}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).toContainComponent(Tool1Component, '(c)');
|
||||
// Activate 'tool-1'
|
||||
router.navigate([{outlets: {toolpanel: 'a'}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).toContainComponent(Tool1Component, '(c)');
|
||||
|
||||
// Deactivate 'tool-1'
|
||||
router.navigate([{outlets: {toolpanel: null}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).not.toContainComponent(Tool1Component, '(d)');
|
||||
// Deactivate 'tool-1'
|
||||
router.navigate([{outlets: {toolpanel: null}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).not.toContainComponent(Tool1Component, '(d)');
|
||||
|
||||
// Activate 'tool-2'
|
||||
router.navigate([{outlets: {toolpanel: 'b'}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).toContainComponent(Tool2Component, '(e)');
|
||||
|
||||
// TODO: remove extra tick for Ivy?
|
||||
tick();
|
||||
}));
|
||||
// Activate 'tool-2'
|
||||
router.navigate([{outlets: {toolpanel: 'b'}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).toContainComponent(Tool2Component, '(e)');
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue