test(ivy): update root causes for @angular/core tests (#27961)

PR Close #27961
This commit is contained in:
Pawel Kozlowski 2019-01-07 17:29:24 +01:00 committed by Kara Erickson
parent e08feb7e54
commit 45880532bf
2 changed files with 76 additions and 81 deletions

View File

@ -1149,89 +1149,85 @@ function declareTests(config?: {useJit: boolean}) {
expect(compRef.instance.someToken).toBe('someRootValue'); expect(compRef.instance.someToken).toBe('someRootValue');
}); });
fixmeIvy('FW-707: TestBed: No LView in getParentInjectorLocation') it('should create a component with the passed NgModuleRef', () => {
.it('should create a component with the passed NgModuleRef', () => { @Component({template: ''})
@Component({template: ''}) class RootComp {
class RootComp { constructor(public vc: ViewContainerRef) {}
constructor(public vc: ViewContainerRef) {} }
}
@Component({template: ''}) @Component({template: ''})
class MyComp { class MyComp {
constructor(@Inject('someToken') public someToken: string) {} constructor(@Inject('someToken') public someToken: string) {}
} }
@NgModule({ @NgModule({
declarations: [RootComp, MyComp], declarations: [RootComp, MyComp],
entryComponents: [MyComp], entryComponents: [MyComp],
providers: [{provide: 'someToken', useValue: 'someRootValue'}], providers: [{provide: 'someToken', useValue: 'someRootValue'}],
}) })
class RootModule { class RootModule {
} }
@NgModule({providers: [{provide: 'someToken', useValue: 'someValue'}]}) @NgModule({providers: [{provide: 'someToken', useValue: 'someValue'}]})
class MyModule { class MyModule {
} }
const compFixture = TestBed.configureTestingModule({imports: [RootModule]}) const compFixture =
.createComponent(RootComp); TestBed.configureTestingModule({imports: [RootModule]}).createComponent(RootComp);
const compiler = <Compiler>TestBed.get(Compiler); const compiler = <Compiler>TestBed.get(Compiler);
const myModule = const myModule = compiler.compileModuleSync(MyModule).create(TestBed.get(NgModuleRef));
compiler.compileModuleSync(MyModule).create(TestBed.get(NgModuleRef)); const myCompFactory = (<ComponentFactoryResolver>TestBed.get(ComponentFactoryResolver))
const myCompFactory = .resolveComponentFactory(MyComp);
(<ComponentFactoryResolver>TestBed.get(ComponentFactoryResolver))
.resolveComponentFactory(MyComp);
// Note: MyComp was declared as entryComponent in the RootModule, // Note: MyComp was declared as entryComponent in the RootModule,
// but we pass MyModule to the createComponent call. // but we pass MyModule to the createComponent call.
// -> expect the providers of MyModule! // -> expect the providers of MyModule!
const compRef = compFixture.componentInstance.vc.createComponent( const compRef = compFixture.componentInstance.vc.createComponent(
myCompFactory, undefined, undefined, undefined, myModule); myCompFactory, undefined, undefined, undefined, myModule);
expect(compRef.instance.someToken).toBe('someValue'); expect(compRef.instance.someToken).toBe('someValue');
}); });
fixmeIvy('FW-707: TestBed: No LView in getParentInjectorLocation') it('should create a component with the NgModuleRef of the ComponentFactoryResolver',
.it('should create a component with the NgModuleRef of the ComponentFactoryResolver', () => {
() => { @Component({template: ''})
@Component({template: ''}) class RootComp {
class RootComp { constructor(public vc: ViewContainerRef) {}
constructor(public vc: ViewContainerRef) {} }
}
@NgModule({ @NgModule({
declarations: [RootComp], declarations: [RootComp],
providers: [{provide: 'someToken', useValue: 'someRootValue'}], providers: [{provide: 'someToken', useValue: 'someRootValue'}],
}) })
class RootModule { class RootModule {
} }
@Component({template: ''}) @Component({template: ''})
class MyComp { class MyComp {
constructor(@Inject('someToken') public someToken: string) {} constructor(@Inject('someToken') public someToken: string) {}
} }
@NgModule({ @NgModule({
declarations: [MyComp], declarations: [MyComp],
entryComponents: [MyComp], entryComponents: [MyComp],
providers: [{provide: 'someToken', useValue: 'someValue'}], providers: [{provide: 'someToken', useValue: 'someValue'}],
}) })
class MyModule { class MyModule {
} }
const compFixture = TestBed.configureTestingModule({imports: [RootModule]}) const compFixture = TestBed.configureTestingModule({imports: [RootModule]})
.createComponent(RootComp); .createComponent(RootComp);
const compiler = <Compiler>TestBed.get(Compiler); const compiler = <Compiler>TestBed.get(Compiler);
const myModule = const myModule =
compiler.compileModuleSync(MyModule).create(TestBed.get(NgModuleRef)); compiler.compileModuleSync(MyModule).create(TestBed.get(NgModuleRef));
const myCompFactory = const myCompFactory =
myModule.componentFactoryResolver.resolveComponentFactory(MyComp); myModule.componentFactoryResolver.resolveComponentFactory(MyComp);
// Note: MyComp was declared as entryComponent in MyModule, // Note: MyComp was declared as entryComponent in MyModule,
// and we don't pass an explicit ModuleRef to the createComponent call. // and we don't pass an explicit ModuleRef to the createComponent call.
// -> expect the providers of MyModule! // -> expect the providers of MyModule!
const compRef = compFixture.componentInstance.vc.createComponent(myCompFactory); const compRef = compFixture.componentInstance.vc.createComponent(myCompFactory);
expect(compRef.instance.someToken).toBe('someValue'); expect(compRef.instance.someToken).toBe('someValue');
}); });
}); });
describe('.insert', () => { describe('.insert', () => {

View File

@ -32,16 +32,15 @@ function declareTests(config?: {useJit: boolean}) {
describe('platform pipes', () => { describe('platform pipes', () => {
beforeEach(() => { TestBed.configureCompiler({...config}); }); beforeEach(() => { TestBed.configureCompiler({...config}); });
fixmeIvy('FW-798: Handle pipes with duplicate names') it('should overwrite them by custom pipes', () => {
.it('should overwrite them by custom pipes', () => { TestBed.configureTestingModule({declarations: [CustomPipe]});
TestBed.configureTestingModule({declarations: [CustomPipe]}); const template = '{{true | somePipe}}';
const template = '{{true | somePipe}}'; TestBed.overrideComponent(MyComp1, {set: {template}});
TestBed.overrideComponent(MyComp1, {set: {template}}); const fixture = TestBed.createComponent(MyComp1);
const fixture = TestBed.createComponent(MyComp1);
fixture.detectChanges(); fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('someCustomPipe'); expect(fixture.nativeElement).toHaveText('someCustomPipe');
}); });
}); });
describe('expressions', () => { describe('expressions', () => {