test(ivy): finish root cause analysis for @angular/core TestBed failing tests (#27510)

PR Close #27510
This commit is contained in:
Pawel Kozlowski
2018-12-06 15:20:11 +01:00
committed by Igor Minar
parent 8fa7e93c30
commit 913563a41d
9 changed files with 130 additions and 123 deletions

View File

@ -69,20 +69,22 @@ function declareTests(config?: {useJit: boolean}) {
expect(childComp.cfr.resolveComponentFactory(ChildComp) !.componentType).toBe(ChildComp);
});
fixmeIvy('unknown').it(
'should not be able to get components from a parent component (content hierarchy)', () => {
TestBed.overrideComponent(
MainComp, {set: {template: '<child><nested></nested></child>'}});
TestBed.overrideComponent(ChildComp, {set: {template: '<ng-content></ng-content>'}});
fixmeIvy(
'FW-805: Ivy\'s implementation of ComponentFactoryResolver doesn\'t have checks present in the view engine')
.it('should not be able to get components from a parent component (content hierarchy)',
() => {
TestBed.overrideComponent(
MainComp, {set: {template: '<child><nested></nested></child>'}});
TestBed.overrideComponent(ChildComp, {set: {template: '<ng-content></ng-content>'}});
const compFixture = TestBed.createComponent(MainComp);
const nestedChildCompEl = compFixture.debugElement.children[0].children[0];
const nestedChildComp: NestedChildComp = nestedChildCompEl.componentInstance;
expect(nestedChildComp.cfr.resolveComponentFactory(ChildComp) !.componentType)
.toBe(ChildComp);
expect(() => nestedChildComp.cfr.resolveComponentFactory(NestedChildComp))
.toThrow(noComponentFactoryError(NestedChildComp));
});
const compFixture = TestBed.createComponent(MainComp);
const nestedChildCompEl = compFixture.debugElement.children[0].children[0];
const nestedChildComp: NestedChildComp = nestedChildCompEl.componentInstance;
expect(nestedChildComp.cfr.resolveComponentFactory(ChildComp) !.componentType)
.toBe(ChildComp);
expect(() => nestedChildComp.cfr.resolveComponentFactory(NestedChildComp))
.toThrow(noComponentFactoryError(NestedChildComp));
});
});
}

View File

@ -1331,21 +1331,24 @@ function declareTests(config?: {useJit: boolean}) {
expect(comp.injectable).toBeAnInstanceOf(InjectableService);
});
fixmeIvy('unknown').it('should support viewProviders', () => {
TestBed.configureTestingModule({
declarations: [MyComp, DirectiveProvidingInjectableInView, DirectiveConsumingInjectable],
schemas: [NO_ERRORS_SCHEMA],
});
const template = `
fixmeIvy(
'FW-804: Injection of view providers with the @Host annotation works differently in ivy')
.it('should support viewProviders', () => {
TestBed.configureTestingModule({
declarations:
[MyComp, DirectiveProvidingInjectableInView, DirectiveConsumingInjectable],
schemas: [NO_ERRORS_SCHEMA],
});
const template = `
<directive-consuming-injectable #consuming>
</directive-consuming-injectable>
`;
TestBed.overrideComponent(DirectiveProvidingInjectableInView, {set: {template}});
const fixture = TestBed.createComponent(DirectiveProvidingInjectableInView);
TestBed.overrideComponent(DirectiveProvidingInjectableInView, {set: {template}});
const fixture = TestBed.createComponent(DirectiveProvidingInjectableInView);
const comp = fixture.debugElement.children[0].references !['consuming'];
expect(comp.injectable).toBeAnInstanceOf(InjectableService);
});
const comp = fixture.debugElement.children[0].references !['consuming'];
expect(comp.injectable).toBeAnInstanceOf(InjectableService);
});
it('should support unbounded lookup', () => {
TestBed.configureTestingModule({

View File

@ -745,12 +745,11 @@ function declareTests(config?: {useJit: boolean}) {
expect(cars[0]).toBe(injector.get(SportsCar));
});
fixmeIvy('FW-682: Compiler error handling')
.it('should throw when the aliased provider does not exist', () => {
const injector = createInjector([{provide: 'car', useExisting: SportsCar}]);
const e = `NullInjectorError: No provider for ${stringify(SportsCar)}!`;
expect(() => injector.get('car')).toThrowError(e);
});
it('should throw when the aliased provider does not exist', () => {
const injector = createInjector([{provide: 'car', useExisting: SportsCar}]);
const e = `NullInjectorError: No provider for ${stringify(SportsCar)}!`;
expect(() => injector.get('car')).toThrowError(e);
});
it('should handle forwardRef in useExisting', () => {
const injector = createInjector([

View File

@ -75,46 +75,43 @@ function declareTests(config?: {useJit: boolean}) {
expect(CountingPipe.calls).toBe(1);
});
fixmeIvy('FW-756: Pipes and directives from imported modules are not taken into account')
.it('should only update the bound property when using asyncPipe - #15205',
fakeAsync(() => {
@Component({template: '<div myDir [a]="p | async" [b]="2"></div>'})
class MyComp {
p = Promise.resolve(1);
}
it('should only update the bound property when using asyncPipe - #15205', fakeAsync(() => {
@Component({template: '<div myDir [a]="p | async" [b]="2"></div>'})
class MyComp {
p = Promise.resolve(1);
}
@Directive({selector: '[myDir]'})
class MyDir {
setterCalls: {[key: string]: any} = {};
// TODO(issue/24571): remove '!'.
changes !: SimpleChanges;
@Directive({selector: '[myDir]'})
class MyDir {
setterCalls: {[key: string]: any} = {};
// TODO(issue/24571): remove '!'.
changes !: SimpleChanges;
@Input()
set a(v: number) { this.setterCalls['a'] = v; }
@Input()
set b(v: number) { this.setterCalls['b'] = v; }
@Input()
set a(v: number) { this.setterCalls['a'] = v; }
@Input()
set b(v: number) { this.setterCalls['b'] = v; }
ngOnChanges(changes: SimpleChanges) { this.changes = changes; }
}
ngOnChanges(changes: SimpleChanges) { this.changes = changes; }
}
TestBed.configureTestingModule({declarations: [MyDir, MyComp]});
const fixture = TestBed.createComponent(MyComp);
const dir =
fixture.debugElement.query(By.directive(MyDir)).injector.get(MyDir) as MyDir;
TestBed.configureTestingModule({declarations: [MyDir, MyComp]});
const fixture = TestBed.createComponent(MyComp);
const dir = fixture.debugElement.query(By.directive(MyDir)).injector.get(MyDir) as MyDir;
fixture.detectChanges();
expect(dir.setterCalls).toEqual({'a': null, 'b': 2});
expect(Object.keys(dir.changes)).toEqual(['a', 'b']);
fixture.detectChanges();
expect(dir.setterCalls).toEqual({'a': null, 'b': 2});
expect(Object.keys(dir.changes)).toEqual(['a', 'b']);
dir.setterCalls = {};
dir.changes = {};
dir.setterCalls = {};
dir.changes = {};
tick();
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(dir.setterCalls).toEqual({'a': 1});
expect(Object.keys(dir.changes)).toEqual(['a']);
}));
expect(dir.setterCalls).toEqual({'a': 1});
expect(Object.keys(dir.changes)).toEqual(['a']);
}));
it('should only evaluate methods once - #10639', () => {
TestBed.configureTestingModule({declarations: [MyCountingComp]});