test(ivy): add ability to find already passing tests (#27449)
PR Close #27449
This commit is contained in:
@ -467,38 +467,38 @@ describe('Integration', () => {
|
||||
expect(location.path()).toEqual('/child/simple');
|
||||
})));
|
||||
|
||||
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]});
|
||||
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]');
|
||||
}));
|
||||
fixture.componentInstance.cond = true;
|
||||
advance(fixture);
|
||||
expect(fixture.nativeElement).toHaveText('[simple]');
|
||||
}));
|
||||
|
||||
it('should update location when navigating', fakeAsync(() => {
|
||||
@Component({template: `record`})
|
||||
@ -2595,46 +2595,46 @@ describe('Integration', () => {
|
||||
expect(canceledStatus).toEqual(false);
|
||||
})));
|
||||
|
||||
fixmeIvy('FW-766: One router test is wrong') &&
|
||||
it('works with componentless routes',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
fixmeIvy('FW-766: One router test is wrong')
|
||||
.it('works with componentless routes',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
||||
router.resetConfig([
|
||||
{
|
||||
path: 'grandparent',
|
||||
canDeactivate: ['RecordingDeactivate'],
|
||||
children: [{
|
||||
path: 'parent',
|
||||
canDeactivate: ['RecordingDeactivate'],
|
||||
children: [{
|
||||
path: 'child',
|
||||
canDeactivate: ['RecordingDeactivate'],
|
||||
children: [{
|
||||
path: 'simple',
|
||||
component: SimpleCmp,
|
||||
canDeactivate: ['RecordingDeactivate']
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
},
|
||||
{path: 'simple', component: SimpleCmp}
|
||||
]);
|
||||
router.resetConfig([
|
||||
{
|
||||
path: 'grandparent',
|
||||
canDeactivate: ['RecordingDeactivate'],
|
||||
children: [{
|
||||
path: 'parent',
|
||||
canDeactivate: ['RecordingDeactivate'],
|
||||
children: [{
|
||||
path: 'child',
|
||||
canDeactivate: ['RecordingDeactivate'],
|
||||
children: [{
|
||||
path: 'simple',
|
||||
component: SimpleCmp,
|
||||
canDeactivate: ['RecordingDeactivate']
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
},
|
||||
{path: 'simple', component: SimpleCmp}
|
||||
]);
|
||||
|
||||
router.navigateByUrl('/grandparent/parent/child/simple');
|
||||
advance(fixture);
|
||||
expect(location.path()).toEqual('/grandparent/parent/child/simple');
|
||||
router.navigateByUrl('/grandparent/parent/child/simple');
|
||||
advance(fixture);
|
||||
expect(location.path()).toEqual('/grandparent/parent/child/simple');
|
||||
|
||||
router.navigateByUrl('/simple');
|
||||
advance(fixture);
|
||||
router.navigateByUrl('/simple');
|
||||
advance(fixture);
|
||||
|
||||
const child = fixture.debugElement.children[1].componentInstance;
|
||||
const child = fixture.debugElement.children[1].componentInstance;
|
||||
|
||||
expect(log.map((a: any) => a.path)).toEqual([
|
||||
'simple', 'child', 'parent', 'grandparent'
|
||||
]);
|
||||
expect(log.map((a: any) => a.component)).toEqual([child, null, null, null]);
|
||||
})));
|
||||
expect(log.map((a: any) => a.path)).toEqual([
|
||||
'simple', 'child', 'parent', 'grandparent'
|
||||
]);
|
||||
expect(log.map((a: any) => a.component)).toEqual([child, null, null, null]);
|
||||
})));
|
||||
|
||||
it('works with aux routes',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
@ -3524,94 +3524,94 @@ describe('Integration', () => {
|
||||
expect(fixture.nativeElement).toHaveText('lazy-loaded-parent [lazy-loaded-child]');
|
||||
})));
|
||||
|
||||
fixmeIvy('FW-646: Directive providers don\'t support primitive types as DI tokens') &&
|
||||
it('should have 2 injector trees: module and element',
|
||||
fakeAsync(inject(
|
||||
[Router, Location, NgModuleFactoryLoader],
|
||||
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
|
||||
@Component({
|
||||
selector: 'lazy',
|
||||
template: 'parent[<router-outlet></router-outlet>]',
|
||||
viewProviders: [
|
||||
{provide: 'shadow', useValue: 'from parent component'},
|
||||
],
|
||||
})
|
||||
class Parent {
|
||||
}
|
||||
fixmeIvy('FW-646: Directive providers don\'t support primitive types as DI tokens')
|
||||
.it('should have 2 injector trees: module and element',
|
||||
fakeAsync(inject(
|
||||
[Router, Location, NgModuleFactoryLoader],
|
||||
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
|
||||
@Component({
|
||||
selector: 'lazy',
|
||||
template: 'parent[<router-outlet></router-outlet>]',
|
||||
viewProviders: [
|
||||
{provide: 'shadow', useValue: 'from parent component'},
|
||||
],
|
||||
})
|
||||
class Parent {
|
||||
}
|
||||
|
||||
@Component({selector: 'lazy', template: 'child'})
|
||||
class Child {
|
||||
}
|
||||
@Component({selector: 'lazy', template: 'child'})
|
||||
class Child {
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [Parent],
|
||||
imports: [RouterModule.forChild([{
|
||||
path: 'parent',
|
||||
component: Parent,
|
||||
children: [
|
||||
{path: 'child', loadChildren: 'child'},
|
||||
]
|
||||
}])],
|
||||
providers: [
|
||||
{provide: 'moduleName', useValue: 'parent'},
|
||||
{provide: 'fromParent', useValue: 'from parent'},
|
||||
],
|
||||
})
|
||||
class ParentModule {
|
||||
}
|
||||
@NgModule({
|
||||
declarations: [Parent],
|
||||
imports: [RouterModule.forChild([{
|
||||
path: 'parent',
|
||||
component: Parent,
|
||||
children: [
|
||||
{path: 'child', loadChildren: 'child'},
|
||||
]
|
||||
}])],
|
||||
providers: [
|
||||
{provide: 'moduleName', useValue: 'parent'},
|
||||
{provide: 'fromParent', useValue: 'from parent'},
|
||||
],
|
||||
})
|
||||
class ParentModule {
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [Child],
|
||||
imports: [RouterModule.forChild([{path: '', component: Child}])],
|
||||
providers: [
|
||||
{provide: 'moduleName', useValue: 'child'},
|
||||
{provide: 'fromChild', useValue: 'from child'},
|
||||
{provide: 'shadow', useValue: 'from child module'},
|
||||
],
|
||||
})
|
||||
class ChildModule {
|
||||
}
|
||||
@NgModule({
|
||||
declarations: [Child],
|
||||
imports: [RouterModule.forChild([{path: '', component: Child}])],
|
||||
providers: [
|
||||
{provide: 'moduleName', useValue: 'child'},
|
||||
{provide: 'fromChild', useValue: 'from child'},
|
||||
{provide: 'shadow', useValue: 'from child module'},
|
||||
],
|
||||
})
|
||||
class ChildModule {
|
||||
}
|
||||
|
||||
loader.stubbedModules = {
|
||||
parent: ParentModule,
|
||||
child: ChildModule,
|
||||
};
|
||||
loader.stubbedModules = {
|
||||
parent: ParentModule,
|
||||
child: ChildModule,
|
||||
};
|
||||
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
router.resetConfig([{path: 'lazy', loadChildren: 'parent'}]);
|
||||
router.navigateByUrl('/lazy/parent/child');
|
||||
advance(fixture);
|
||||
expect(location.path()).toEqual('/lazy/parent/child');
|
||||
expect(fixture.nativeElement).toHaveText('parent[child]');
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
router.resetConfig([{path: 'lazy', loadChildren: 'parent'}]);
|
||||
router.navigateByUrl('/lazy/parent/child');
|
||||
advance(fixture);
|
||||
expect(location.path()).toEqual('/lazy/parent/child');
|
||||
expect(fixture.nativeElement).toHaveText('parent[child]');
|
||||
|
||||
const pInj = fixture.debugElement.query(By.directive(Parent)).injector !;
|
||||
const cInj = fixture.debugElement.query(By.directive(Child)).injector !;
|
||||
const pInj = fixture.debugElement.query(By.directive(Parent)).injector !;
|
||||
const cInj = fixture.debugElement.query(By.directive(Child)).injector !;
|
||||
|
||||
expect(pInj.get('moduleName')).toEqual('parent');
|
||||
expect(pInj.get('fromParent')).toEqual('from parent');
|
||||
expect(pInj.get(Parent)).toBeAnInstanceOf(Parent);
|
||||
expect(pInj.get('fromChild', null)).toEqual(null);
|
||||
expect(pInj.get(Child, null)).toEqual(null);
|
||||
expect(pInj.get('moduleName')).toEqual('parent');
|
||||
expect(pInj.get('fromParent')).toEqual('from parent');
|
||||
expect(pInj.get(Parent)).toBeAnInstanceOf(Parent);
|
||||
expect(pInj.get('fromChild', null)).toEqual(null);
|
||||
expect(pInj.get(Child, null)).toEqual(null);
|
||||
|
||||
expect(cInj.get('moduleName')).toEqual('child');
|
||||
expect(cInj.get('fromParent')).toEqual('from parent');
|
||||
expect(cInj.get('fromChild')).toEqual('from child');
|
||||
expect(cInj.get(Parent)).toBeAnInstanceOf(Parent);
|
||||
expect(cInj.get(Child)).toBeAnInstanceOf(Child);
|
||||
// The child module can not shadow the parent component
|
||||
expect(cInj.get('shadow')).toEqual('from parent component');
|
||||
expect(cInj.get('moduleName')).toEqual('child');
|
||||
expect(cInj.get('fromParent')).toEqual('from parent');
|
||||
expect(cInj.get('fromChild')).toEqual('from child');
|
||||
expect(cInj.get(Parent)).toBeAnInstanceOf(Parent);
|
||||
expect(cInj.get(Child)).toBeAnInstanceOf(Child);
|
||||
// The child module can not shadow the parent component
|
||||
expect(cInj.get('shadow')).toEqual('from parent component');
|
||||
|
||||
const pmInj = pInj.get(NgModuleRef).injector;
|
||||
const cmInj = cInj.get(NgModuleRef).injector;
|
||||
const pmInj = pInj.get(NgModuleRef).injector;
|
||||
const cmInj = cInj.get(NgModuleRef).injector;
|
||||
|
||||
expect(pmInj.get('moduleName')).toEqual('parent');
|
||||
expect(cmInj.get('moduleName')).toEqual('child');
|
||||
expect(pmInj.get('moduleName')).toEqual('parent');
|
||||
expect(cmInj.get('moduleName')).toEqual('child');
|
||||
|
||||
expect(pmInj.get(Parent, '-')).toEqual('-');
|
||||
expect(cmInj.get(Parent, '-')).toEqual('-');
|
||||
expect(pmInj.get(Child, '-')).toEqual('-');
|
||||
expect(cmInj.get(Child, '-')).toEqual('-');
|
||||
})));
|
||||
expect(pmInj.get(Parent, '-')).toEqual('-');
|
||||
expect(cmInj.get(Parent, '-')).toEqual('-');
|
||||
expect(pmInj.get(Child, '-')).toEqual('-');
|
||||
expect(cmInj.get(Child, '-')).toEqual('-');
|
||||
})));
|
||||
|
||||
// https://github.com/angular/angular/issues/12889
|
||||
it('should create a single instance of lazy-loaded modules',
|
||||
@ -3653,56 +3653,56 @@ describe('Integration', () => {
|
||||
|
||||
// https://github.com/angular/angular/issues/13870
|
||||
fixmeIvy(
|
||||
'FW-767: Lazy loaded modules are not used when resolving dependencies in one of their components') &&
|
||||
it('should create a single instance of guards for lazy-loaded modules',
|
||||
fakeAsync(inject(
|
||||
[Router, Location, NgModuleFactoryLoader],
|
||||
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
|
||||
@Injectable()
|
||||
class Service {
|
||||
}
|
||||
'FW-767: Lazy loaded modules are not used when resolving dependencies in one of their components')
|
||||
.it('should create a single instance of guards for lazy-loaded modules',
|
||||
fakeAsync(inject(
|
||||
[Router, Location, NgModuleFactoryLoader],
|
||||
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
|
||||
@Injectable()
|
||||
class Service {
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class Resolver implements Resolve<Service> {
|
||||
constructor(public service: Service) {}
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
return this.service;
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
class Resolver implements Resolve<Service> {
|
||||
constructor(public service: Service) {}
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
return this.service;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'lazy', template: 'lazy'})
|
||||
class LazyLoadedComponent {
|
||||
resolvedService: Service;
|
||||
constructor(public injectedService: Service, route: ActivatedRoute) {
|
||||
this.resolvedService = route.snapshot.data['service'];
|
||||
}
|
||||
}
|
||||
@Component({selector: 'lazy', template: 'lazy'})
|
||||
class LazyLoadedComponent {
|
||||
resolvedService: Service;
|
||||
constructor(public injectedService: Service, route: ActivatedRoute) {
|
||||
this.resolvedService = route.snapshot.data['service'];
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [LazyLoadedComponent],
|
||||
providers: [Service, Resolver],
|
||||
imports: [
|
||||
RouterModule.forChild([{
|
||||
path: 'loaded',
|
||||
component: LazyLoadedComponent,
|
||||
resolve: {'service': Resolver},
|
||||
}]),
|
||||
]
|
||||
})
|
||||
class LoadedModule {
|
||||
}
|
||||
@NgModule({
|
||||
declarations: [LazyLoadedComponent],
|
||||
providers: [Service, Resolver],
|
||||
imports: [
|
||||
RouterModule.forChild([{
|
||||
path: 'loaded',
|
||||
component: LazyLoadedComponent,
|
||||
resolve: {'service': Resolver},
|
||||
}]),
|
||||
]
|
||||
})
|
||||
class LoadedModule {
|
||||
}
|
||||
|
||||
loader.stubbedModules = {expected: LoadedModule};
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
router.resetConfig([{path: 'lazy', loadChildren: 'expected'}]);
|
||||
router.navigateByUrl('/lazy/loaded');
|
||||
advance(fixture);
|
||||
loader.stubbedModules = {expected: LoadedModule};
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
router.resetConfig([{path: 'lazy', loadChildren: 'expected'}]);
|
||||
router.navigateByUrl('/lazy/loaded');
|
||||
advance(fixture);
|
||||
|
||||
expect(fixture.nativeElement).toHaveText('lazy');
|
||||
const lzc = fixture.debugElement.query(By.directive(LazyLoadedComponent))
|
||||
.componentInstance;
|
||||
expect(lzc.injectedService).toBe(lzc.resolvedService);
|
||||
})));
|
||||
expect(fixture.nativeElement).toHaveText('lazy');
|
||||
const lzc = fixture.debugElement.query(By.directive(LazyLoadedComponent))
|
||||
.componentInstance;
|
||||
expect(lzc.injectedService).toBe(lzc.resolvedService);
|
||||
})));
|
||||
|
||||
|
||||
it('should emit RouteConfigLoadStart and RouteConfigLoadEnd event when route is lazy loaded',
|
||||
@ -3954,27 +3954,27 @@ describe('Integration', () => {
|
||||
});
|
||||
|
||||
fixmeIvy(
|
||||
'FW-767: Lazy loaded modules are not used when resolving dependencies in one of their components') &&
|
||||
it('should use the injector of the lazily-loaded configuration',
|
||||
fakeAsync(inject(
|
||||
[Router, Location, NgModuleFactoryLoader],
|
||||
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
|
||||
loader.stubbedModules = {expected: LoadedModule};
|
||||
'FW-767: Lazy loaded modules are not used when resolving dependencies in one of their components')
|
||||
.it('should use the injector of the lazily-loaded configuration',
|
||||
fakeAsync(inject(
|
||||
[Router, Location, NgModuleFactoryLoader],
|
||||
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
|
||||
loader.stubbedModules = {expected: LoadedModule};
|
||||
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
||||
router.resetConfig([{
|
||||
path: 'eager-parent',
|
||||
component: EagerParentComponent,
|
||||
children: [{path: 'lazy', loadChildren: 'expected'}]
|
||||
}]);
|
||||
router.resetConfig([{
|
||||
path: 'eager-parent',
|
||||
component: EagerParentComponent,
|
||||
children: [{path: 'lazy', loadChildren: 'expected'}]
|
||||
}]);
|
||||
|
||||
router.navigateByUrl('/eager-parent/lazy/lazy-parent/lazy-child');
|
||||
advance(fixture);
|
||||
router.navigateByUrl('/eager-parent/lazy/lazy-parent/lazy-child');
|
||||
advance(fixture);
|
||||
|
||||
expect(location.path()).toEqual('/eager-parent/lazy/lazy-parent/lazy-child');
|
||||
expect(fixture.nativeElement).toHaveText('eager-parent lazy-parent lazy-child');
|
||||
})));
|
||||
expect(location.path()).toEqual('/eager-parent/lazy/lazy-parent/lazy-child');
|
||||
expect(fixture.nativeElement).toHaveText('eager-parent lazy-parent lazy-child');
|
||||
})));
|
||||
});
|
||||
|
||||
it('works when given a callback',
|
||||
@ -4439,82 +4439,82 @@ describe('Integration', () => {
|
||||
expect(simpleCmp1).not.toBe(simpleCmp2);
|
||||
})));
|
||||
|
||||
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;
|
||||
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)');
|
||||
}));
|
||||
// Activate 'tool-2'
|
||||
router.navigate([{outlets: {toolpanel: 'b'}}]);
|
||||
advance(fixture);
|
||||
expect(fixture).toContainComponent(Tool2Component, '(e)');
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -62,64 +62,64 @@ describe('RouterPreloader', () => {
|
||||
|
||||
|
||||
fixmeIvy(
|
||||
'FW-765: NgModuleRef hierarchy is differently constructed when the router preloads modules') &&
|
||||
it('should work',
|
||||
fakeAsync(inject(
|
||||
[NgModuleFactoryLoader, RouterPreloader, Router, NgModuleRef],
|
||||
(loader: SpyNgModuleFactoryLoader, preloader: RouterPreloader, router: Router,
|
||||
testModule: NgModuleRef<any>) => {
|
||||
const events: Array<RouteConfigLoadStart|RouteConfigLoadEnd> = [];
|
||||
@NgModule({
|
||||
declarations: [LazyLoadedCmp],
|
||||
imports: [RouterModule.forChild(
|
||||
[{path: 'LoadedModule2', component: LazyLoadedCmp}])]
|
||||
})
|
||||
class LoadedModule2 {
|
||||
}
|
||||
'FW-765: NgModuleRef hierarchy is differently constructed when the router preloads modules')
|
||||
.it('should work',
|
||||
fakeAsync(inject(
|
||||
[NgModuleFactoryLoader, RouterPreloader, Router, NgModuleRef],
|
||||
(loader: SpyNgModuleFactoryLoader, preloader: RouterPreloader, router: Router,
|
||||
testModule: NgModuleRef<any>) => {
|
||||
const events: Array<RouteConfigLoadStart|RouteConfigLoadEnd> = [];
|
||||
@NgModule({
|
||||
declarations: [LazyLoadedCmp],
|
||||
imports: [RouterModule.forChild(
|
||||
[{path: 'LoadedModule2', component: LazyLoadedCmp}])]
|
||||
})
|
||||
class LoadedModule2 {
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(
|
||||
[{path: 'LoadedModule1', loadChildren: 'expected2'}])]
|
||||
})
|
||||
class LoadedModule1 {
|
||||
}
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(
|
||||
[{path: 'LoadedModule1', loadChildren: 'expected2'}])]
|
||||
})
|
||||
class LoadedModule1 {
|
||||
}
|
||||
|
||||
router.events.subscribe(e => {
|
||||
if (e instanceof RouteConfigLoadEnd || e instanceof RouteConfigLoadStart) {
|
||||
events.push(e);
|
||||
}
|
||||
});
|
||||
router.events.subscribe(e => {
|
||||
if (e instanceof RouteConfigLoadEnd || e instanceof RouteConfigLoadStart) {
|
||||
events.push(e);
|
||||
}
|
||||
});
|
||||
|
||||
loader.stubbedModules = {
|
||||
expected: LoadedModule1,
|
||||
expected2: LoadedModule2,
|
||||
};
|
||||
loader.stubbedModules = {
|
||||
expected: LoadedModule1,
|
||||
expected2: LoadedModule2,
|
||||
};
|
||||
|
||||
preloader.preload().subscribe(() => {});
|
||||
preloader.preload().subscribe(() => {});
|
||||
|
||||
tick();
|
||||
tick();
|
||||
|
||||
const c = router.config;
|
||||
expect(c[0].loadChildren).toEqual('expected');
|
||||
const c = router.config;
|
||||
expect(c[0].loadChildren).toEqual('expected');
|
||||
|
||||
const loadedConfig: LoadedRouterConfig = (c[0] as any)._loadedConfig !;
|
||||
const module: any = loadedConfig.module;
|
||||
expect(loadedConfig.routes[0].path).toEqual('LoadedModule1');
|
||||
expect(module._parent).toBe(testModule);
|
||||
const loadedConfig: LoadedRouterConfig = (c[0] as any)._loadedConfig !;
|
||||
const module: any = loadedConfig.module;
|
||||
expect(loadedConfig.routes[0].path).toEqual('LoadedModule1');
|
||||
expect(module._parent).toBe(testModule);
|
||||
|
||||
const loadedConfig2: LoadedRouterConfig =
|
||||
(loadedConfig.routes[0] as any)._loadedConfig !;
|
||||
const module2: any = loadedConfig2.module;
|
||||
expect(loadedConfig2.routes[0].path).toEqual('LoadedModule2');
|
||||
expect(module2._parent).toBe(module);
|
||||
const loadedConfig2: LoadedRouterConfig =
|
||||
(loadedConfig.routes[0] as any)._loadedConfig !;
|
||||
const module2: any = loadedConfig2.module;
|
||||
expect(loadedConfig2.routes[0].path).toEqual('LoadedModule2');
|
||||
expect(module2._parent).toBe(module);
|
||||
|
||||
expect(events.map(e => e.toString())).toEqual([
|
||||
'RouteConfigLoadStart(path: lazy)',
|
||||
'RouteConfigLoadEnd(path: lazy)',
|
||||
'RouteConfigLoadStart(path: LoadedModule1)',
|
||||
'RouteConfigLoadEnd(path: LoadedModule1)',
|
||||
]);
|
||||
})));
|
||||
expect(events.map(e => e.toString())).toEqual([
|
||||
'RouteConfigLoadStart(path: lazy)',
|
||||
'RouteConfigLoadEnd(path: lazy)',
|
||||
'RouteConfigLoadStart(path: LoadedModule1)',
|
||||
'RouteConfigLoadEnd(path: LoadedModule1)',
|
||||
]);
|
||||
})));
|
||||
});
|
||||
|
||||
describe('should support modules that have already been loaded', () => {
|
||||
@ -131,59 +131,59 @@ describe('RouterPreloader', () => {
|
||||
});
|
||||
|
||||
fixmeIvy(
|
||||
'FW-765: NgModuleRef hierarchy is differently constructed when the router preloads modules') &&
|
||||
it('should work',
|
||||
fakeAsync(inject(
|
||||
[NgModuleFactoryLoader, RouterPreloader, Router, NgModuleRef, Compiler],
|
||||
(loader: SpyNgModuleFactoryLoader, preloader: RouterPreloader, router: Router,
|
||||
testModule: NgModuleRef<any>, compiler: Compiler) => {
|
||||
@NgModule()
|
||||
class LoadedModule2 {
|
||||
}
|
||||
'FW-765: NgModuleRef hierarchy is differently constructed when the router preloads modules')
|
||||
.it('should work',
|
||||
fakeAsync(inject(
|
||||
[NgModuleFactoryLoader, RouterPreloader, Router, NgModuleRef, Compiler],
|
||||
(loader: SpyNgModuleFactoryLoader, preloader: RouterPreloader, router: Router,
|
||||
testModule: NgModuleRef<any>, compiler: Compiler) => {
|
||||
@NgModule()
|
||||
class LoadedModule2 {
|
||||
}
|
||||
|
||||
const module2 = compiler.compileModuleSync(LoadedModule2).create(null);
|
||||
const module2 = compiler.compileModuleSync(LoadedModule2).create(null);
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild([
|
||||
<Route>{
|
||||
path: 'LoadedModule2',
|
||||
loadChildren: 'no',
|
||||
_loadedConfig: {
|
||||
routes: [{path: 'LoadedModule3', loadChildren: 'expected3'}],
|
||||
module: module2,
|
||||
}
|
||||
},
|
||||
])]
|
||||
})
|
||||
class LoadedModule1 {
|
||||
}
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild([
|
||||
<Route>{
|
||||
path: 'LoadedModule2',
|
||||
loadChildren: 'no',
|
||||
_loadedConfig: {
|
||||
routes: [{path: 'LoadedModule3', loadChildren: 'expected3'}],
|
||||
module: module2,
|
||||
}
|
||||
},
|
||||
])]
|
||||
})
|
||||
class LoadedModule1 {
|
||||
}
|
||||
|
||||
@NgModule({imports: [RouterModule.forChild([])]})
|
||||
class LoadedModule3 {
|
||||
}
|
||||
@NgModule({imports: [RouterModule.forChild([])]})
|
||||
class LoadedModule3 {
|
||||
}
|
||||
|
||||
loader.stubbedModules = {
|
||||
expected: LoadedModule1,
|
||||
expected3: LoadedModule3,
|
||||
};
|
||||
loader.stubbedModules = {
|
||||
expected: LoadedModule1,
|
||||
expected3: LoadedModule3,
|
||||
};
|
||||
|
||||
preloader.preload().subscribe(() => {});
|
||||
preloader.preload().subscribe(() => {});
|
||||
|
||||
tick();
|
||||
tick();
|
||||
|
||||
const c = router.config;
|
||||
const c = router.config;
|
||||
|
||||
const loadedConfig: LoadedRouterConfig = (c[0] as any)._loadedConfig !;
|
||||
const module: any = loadedConfig.module;
|
||||
expect(module._parent).toBe(testModule);
|
||||
const loadedConfig: LoadedRouterConfig = (c[0] as any)._loadedConfig !;
|
||||
const module: any = loadedConfig.module;
|
||||
expect(module._parent).toBe(testModule);
|
||||
|
||||
const loadedConfig2: LoadedRouterConfig =
|
||||
(loadedConfig.routes[0] as any)._loadedConfig !;
|
||||
const loadedConfig3: LoadedRouterConfig =
|
||||
(loadedConfig2.routes[0] as any)._loadedConfig !;
|
||||
const module3: any = loadedConfig3.module;
|
||||
expect(module3._parent).toBe(module2);
|
||||
})));
|
||||
const loadedConfig2: LoadedRouterConfig =
|
||||
(loadedConfig.routes[0] as any)._loadedConfig !;
|
||||
const loadedConfig3: LoadedRouterConfig =
|
||||
(loadedConfig2.routes[0] as any)._loadedConfig !;
|
||||
const module3: any = loadedConfig3.module;
|
||||
expect(module3._parent).toBe(module2);
|
||||
})));
|
||||
});
|
||||
|
||||
describe('should ignore errors', () => {
|
||||
|
Reference in New Issue
Block a user