test(ivy): root cause analysis for platform-browser (#27460)

PR Close #27460
This commit is contained in:
Olivier Combe 2018-12-04 17:51:34 +01:00 committed by Igor Minar
parent c07afd9db1
commit 9062b391a2
2 changed files with 212 additions and 190 deletions

View File

@ -160,7 +160,7 @@ function bootstrap(
afterEach(destroyPlatform); afterEach(destroyPlatform);
fixmeIvy('unknown') && fixmeIvy('FW-553: TestBed is unaware of async compilation') &&
it('should throw if bootstrapped Directive is not a Component', it('should throw if bootstrapped Directive is not a Component',
inject([AsyncTestCompleter], (done: AsyncTestCompleter) => { inject([AsyncTestCompleter], (done: AsyncTestCompleter) => {
const logger = new MockConsole(); const logger = new MockConsole();
@ -188,7 +188,7 @@ function bootstrap(
}); });
})); }));
fixmeIvy('unknown') && fixmeIvy('FW-553: TestBed is unaware of async compilation') &&
it('should throw if no provider', it('should throw if no provider',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const logger = new MockConsole(); const logger = new MockConsole();

View File

@ -10,7 +10,7 @@ import {CompilerConfig, ResourceLoader} from '@angular/compiler';
import {CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, Directive, Inject, Injectable, Injector, Input, NgModule, Optional, Pipe, SkipSelf, ɵstringify as stringify} from '@angular/core'; import {CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, Directive, Inject, Injectable, Injector, Input, NgModule, Optional, Pipe, SkipSelf, ɵstringify as stringify} from '@angular/core';
import {TestBed, async, fakeAsync, getTestBed, inject, tick, withModule} from '@angular/core/testing'; import {TestBed, async, fakeAsync, getTestBed, inject, tick, withModule} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/src/matchers'; import {expect} from '@angular/platform-browser/testing/src/matchers';
import {fixmeIvy} from '@angular/private/testing'; import {fixmeIvy, obsoleteInIvy} from '@angular/private/testing';
// Services, and components for the tests. // Services, and components for the tests.
@ -251,7 +251,8 @@ class CompWithUrlTemplate {
expect(compFixture.componentInstance).toBeAnInstanceOf(CompUsingModuleDirectiveAndPipe); expect(compFixture.componentInstance).toBeAnInstanceOf(CompUsingModuleDirectiveAndPipe);
}); });
fixmeIvy('unknown') && it('should use set up directives and pipes', () => { fixmeIvy('FW-681: not possible to retrieve host property bindings from TView') &&
it('should use set up directives and pipes', () => {
const compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe); const compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe);
const el = compFixture.debugElement; const el = compFixture.debugElement;
@ -288,7 +289,7 @@ class CompWithUrlTemplate {
expect(service.value).toEqual('real value'); expect(service.value).toEqual('real value');
})); }));
fixmeIvy('unknown') && fixmeIvy('FW-681: not possible to retrieve host property bindings from TView') &&
it('should use set up directives and pipes', withModule(moduleConfig, () => { it('should use set up directives and pipes', withModule(moduleConfig, () => {
const compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe); const compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe);
const el = compFixture.debugElement; const el = compFixture.debugElement;
@ -309,7 +310,7 @@ class CompWithUrlTemplate {
TestBed.compileComponents(); TestBed.compileComponents();
})); }));
fixmeIvy('unknown') && isBrowser && fixmeIvy('FW-553: TestBed is unaware of async compilation') && isBrowser &&
it('should allow to createSync components with templateUrl after explicit async compilation', it('should allow to createSync components with templateUrl after explicit async compilation',
() => { () => {
const fixture = TestBed.createComponent(CompWithUrlTemplate); const fixture = TestBed.createComponent(CompWithUrlTemplate);
@ -370,7 +371,8 @@ class CompWithUrlTemplate {
.overrideDirective( .overrideDirective(
SomeDirective, {set: {selector: '[someDir]', host: {'[title]': 'someProp'}}}); SomeDirective, {set: {selector: '[someDir]', host: {'[title]': 'someProp'}}});
}); });
fixmeIvy('unknown') && it('should work', () => { fixmeIvy('FW-681: not possible to retrieve host property bindings from TView') &&
it('should work', () => {
const compFixture = TestBed.createComponent(SomeComponent); const compFixture = TestBed.createComponent(SomeComponent);
compFixture.detectChanges(); compFixture.detectChanges();
expect(compFixture.debugElement.children[0].properties['title']).toEqual('hello'); expect(compFixture.debugElement.children[0].properties['title']).toEqual('hello');
@ -385,7 +387,8 @@ class CompWithUrlTemplate {
.overridePipe(SomePipe, {set: {name: 'somePipe'}}) .overridePipe(SomePipe, {set: {name: 'somePipe'}})
.overridePipe(SomePipe, {add: {pure: false}}); .overridePipe(SomePipe, {add: {pure: false}});
}); });
fixmeIvy('unknown') && it('should work', () => { fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should work', () => {
const compFixture = TestBed.createComponent(SomeComponent); const compFixture = TestBed.createComponent(SomeComponent);
compFixture.detectChanges(); compFixture.detectChanges();
expect(compFixture.nativeElement).toHaveText('transformed hello'); expect(compFixture.nativeElement).toHaveText('transformed hello');
@ -455,7 +458,8 @@ class CompWithUrlTemplate {
expect(TestBed.get('a')).toBe('mockA: depValue'); expect(TestBed.get('a')).toBe('mockA: depValue');
}); });
fixmeIvy('unknown') && it('should support SkipSelf', () => { fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should support SkipSelf', () => {
@NgModule({ @NgModule({
providers: [ providers: [
{provide: 'a', useValue: 'aValue'}, {provide: 'a', useValue: 'aValue'},
@ -466,13 +470,15 @@ class CompWithUrlTemplate {
} }
TestBed.overrideProvider( TestBed.overrideProvider(
'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new SkipSelf(), 'dep']]}); 'a',
{useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new SkipSelf(), 'dep']]});
TestBed.configureTestingModule( TestBed.configureTestingModule(
{providers: [{provide: 'dep', useValue: 'parentDepValue'}]}); {providers: [{provide: 'dep', useValue: 'parentDepValue'}]});
const compiler = TestBed.get(Compiler) as Compiler; const compiler = TestBed.get(Compiler) as Compiler;
const modFactory = compiler.compileModuleSync(MyModule); const modFactory = compiler.compileModuleSync(MyModule);
expect(modFactory.create(getTestBed()).injector.get('a')).toBe('mockA: parentDepValue'); expect(modFactory.create(getTestBed()).injector.get('a'))
.toBe('mockA: parentDepValue');
}); });
it('should keep imported NgModules eager', () => { it('should keep imported NgModules eager', () => {
@ -495,7 +501,7 @@ class CompWithUrlTemplate {
expect(someModule).toBeAnInstanceOf(SomeModule); expect(someModule).toBeAnInstanceOf(SomeModule);
}); });
fixmeIvy('unknown') && obsoleteInIvy(`deprecated method, won't be reimplemented for Render3`) &&
it('should keep imported NgModules lazy with deprecatedOverrideProvider', () => { it('should keep imported NgModules lazy with deprecatedOverrideProvider', () => {
let someModule: SomeModule|undefined; let someModule: SomeModule|undefined;
@ -547,7 +553,8 @@ class CompWithUrlTemplate {
}); });
describe('in Components', () => { describe('in Components', () => {
fixmeIvy('unknown') && it('should support useValue', () => { fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should support useValue', () => {
@Component({ @Component({
template: '', template: '',
providers: [ providers: [
@ -564,7 +571,8 @@ class CompWithUrlTemplate {
expect(ctx.debugElement.injector.get('a')).toBe('mockValue'); expect(ctx.debugElement.injector.get('a')).toBe('mockValue');
}); });
fixmeIvy('unknown') && it('should support useFactory', () => { fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should support useFactory', () => {
@Component({ @Component({
template: '', template: '',
providers: [ providers: [
@ -577,13 +585,14 @@ class CompWithUrlTemplate {
TestBed.overrideProvider( TestBed.overrideProvider(
'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: ['dep']}); 'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: ['dep']});
const ctx = const ctx = TestBed.configureTestingModule({declarations: [MyComp]})
TestBed.configureTestingModule({declarations: [MyComp]}).createComponent(MyComp); .createComponent(MyComp);
expect(ctx.debugElement.injector.get('a')).toBe('mockA: depValue'); expect(ctx.debugElement.injector.get('a')).toBe('mockA: depValue');
}); });
fixmeIvy('unknown') && it('should support @Optional without matches', () => { fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should support @Optional without matches', () => {
@Component({ @Component({
template: '', template: '',
providers: [ providers: [
@ -594,14 +603,16 @@ class CompWithUrlTemplate {
} }
TestBed.overrideProvider( TestBed.overrideProvider(
'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new Optional(), 'dep']]}); 'a',
const ctx = {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new Optional(), 'dep']]});
TestBed.configureTestingModule({declarations: [MyComp]}).createComponent(MyComp); const ctx = TestBed.configureTestingModule({declarations: [MyComp]})
.createComponent(MyComp);
expect(ctx.debugElement.injector.get('a')).toBe('mockA: null'); expect(ctx.debugElement.injector.get('a')).toBe('mockA: null');
}); });
fixmeIvy('unknown') && it('should support Optional with matches', () => { fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should support Optional with matches', () => {
@Component({ @Component({
template: '', template: '',
providers: [ providers: [
@ -613,14 +624,16 @@ class CompWithUrlTemplate {
} }
TestBed.overrideProvider( TestBed.overrideProvider(
'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new Optional(), 'dep']]}); 'a',
const ctx = {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new Optional(), 'dep']]});
TestBed.configureTestingModule({declarations: [MyComp]}).createComponent(MyComp); const ctx = TestBed.configureTestingModule({declarations: [MyComp]})
.createComponent(MyComp);
expect(ctx.debugElement.injector.get('a')).toBe('mockA: depValue'); expect(ctx.debugElement.injector.get('a')).toBe('mockA: depValue');
}); });
fixmeIvy('unknown') && it('should support SkipSelf', () => { fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should support SkipSelf', () => {
@Directive({ @Directive({
selector: '[myDir]', selector: '[myDir]',
providers: [ providers: [
@ -641,13 +654,16 @@ class CompWithUrlTemplate {
} }
TestBed.overrideProvider( TestBed.overrideProvider(
'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new SkipSelf(), 'dep']]}); 'a',
{useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new SkipSelf(), 'dep']]});
const ctx = TestBed.configureTestingModule({declarations: [MyComp, MyDir]}) const ctx = TestBed.configureTestingModule({declarations: [MyComp, MyDir]})
.createComponent(MyComp); .createComponent(MyComp);
expect(ctx.debugElement.children[0].injector.get('a')).toBe('mockA: parentDepValue'); expect(ctx.debugElement.children[0].injector.get('a'))
.toBe('mockA: parentDepValue');
}); });
fixmeIvy('unknown') && it('should support multiple providers in a template', () => { fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should support multiple providers in a template', () => {
@Directive({ @Directive({
selector: '[myDir1]', selector: '[myDir1]',
providers: [ providers: [
@ -692,7 +708,8 @@ class CompWithUrlTemplate {
constructor(@Inject('a') a: any, @Inject('b') b: any) {} constructor(@Inject('a') a: any, @Inject('b') b: any) {}
} }
fixmeIvy('unknown') && fixmeIvy(
'FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should inject providers that were declared before it', () => { it('should inject providers that were declared before it', () => {
TestBed.overrideProvider( TestBed.overrideProvider(
'b', {useFactory: (a: string) => `mockB: ${a}`, deps: ['a']}); 'b', {useFactory: (a: string) => `mockB: ${a}`, deps: ['a']});
@ -702,7 +719,8 @@ class CompWithUrlTemplate {
expect(ctx.debugElement.injector.get('b')).toBe('mockB: aValue'); expect(ctx.debugElement.injector.get('b')).toBe('mockB: aValue');
}); });
fixmeIvy('unknown') && fixmeIvy(
'FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should inject providers that were declared after it', () => { it('should inject providers that were declared after it', () => {
TestBed.overrideProvider( TestBed.overrideProvider(
'a', {useFactory: (b: string) => `mockA: ${b}`, deps: ['b']}); 'a', {useFactory: (b: string) => `mockA: ${b}`, deps: ['b']});
@ -723,7 +741,7 @@ class CompWithUrlTemplate {
}); });
describe('overrideTemplateUsingTestingModule', () => { describe('overrideTemplateUsingTestingModule', () => {
fixmeIvy('unknown') && fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should compile the template in the context of the testing module', () => { it('should compile the template in the context of the testing module', () => {
@Component({selector: 'comp', template: 'a'}) @Component({selector: 'comp', template: 'a'})
class MyComponent { class MyComponent {
@ -752,7 +770,8 @@ class CompWithUrlTemplate {
expect(testDir !.test).toBe('some prop'); expect(testDir !.test).toBe('some prop');
}); });
fixmeIvy('unknown') && it('should throw if the TestBed is already created', () => { fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should throw if the TestBed is already created', () => {
@Component({selector: 'comp', template: 'a'}) @Component({selector: 'comp', template: 'a'})
class MyComponent { class MyComponent {
} }
@ -764,7 +783,7 @@ class CompWithUrlTemplate {
/Cannot override template when the test module has already been instantiated/); /Cannot override template when the test module has already been instantiated/);
}); });
fixmeIvy('unknown') && fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') &&
it('should reset overrides when the testing module is resetted', () => { it('should reset overrides when the testing module is resetted', () => {
@Component({selector: 'comp', template: 'a'}) @Component({selector: 'comp', template: 'a'})
class MyComponent { class MyComponent {
@ -790,25 +809,27 @@ class CompWithUrlTemplate {
{providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]}); {providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]});
}); });
fixmeIvy('unknown') && it('should use set up providers', fakeAsync(() => { fixmeIvy('FW-553: TestBed is unaware of async compilation') &&
it('should use set up providers', fakeAsync(() => {
TestBed.compileComponents(); TestBed.compileComponents();
tick(); tick();
const compFixture = const compFixture = TestBed.createComponent(CompWithUrlTemplate);
TestBed.createComponent(CompWithUrlTemplate);
expect(compFixture.nativeElement).toHaveText('Hello world!'); expect(compFixture.nativeElement).toHaveText('Hello world!');
})); }));
}); });
describe('useJit true', () => { describe('useJit true', () => {
beforeEach(() => TestBed.configureCompiler({useJit: true})); beforeEach(() => TestBed.configureCompiler({useJit: true}));
fixmeIvy('unknown') && it('should set the value into CompilerConfig', obsoleteInIvy('the Render3 compiler JiT mode is not configurable') &&
it('should set the value into CompilerConfig',
inject([CompilerConfig], (config: CompilerConfig) => { inject([CompilerConfig], (config: CompilerConfig) => {
expect(config.useJit).toBe(true); expect(config.useJit).toBe(true);
})); }));
}); });
describe('useJit false', () => { describe('useJit false', () => {
beforeEach(() => TestBed.configureCompiler({useJit: false})); beforeEach(() => TestBed.configureCompiler({useJit: false}));
fixmeIvy('unknown') && it('should set the value into CompilerConfig', obsoleteInIvy('the Render3 compiler JiT mode is not configurable') &&
it('should set the value into CompilerConfig',
inject([CompilerConfig], (config: CompilerConfig) => { inject([CompilerConfig], (config: CompilerConfig) => {
expect(config.useJit).toBe(false); expect(config.useJit).toBe(false);
})); }));
@ -900,7 +921,7 @@ class CompWithUrlTemplate {
{providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]}); {providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]});
}); });
fixmeIvy('unknown') && fixmeIvy('FW-553: TestBed is unaware of async compilation') &&
it('should report an error for declared components with templateUrl which never call TestBed.compileComponents', it('should report an error for declared components with templateUrl which never call TestBed.compileComponents',
() => { () => {
const itPromise = patchJasmineIt(); const itPromise = patchJasmineIt();
@ -919,7 +940,8 @@ class CompWithUrlTemplate {
}); });
fixmeIvy('unknown') &&
fixmeIvy(`FW-721: Bindings to unknown properties are not reported as errors`) &&
it('should error on unknown bound properties on custom elements by default', () => { it('should error on unknown bound properties on custom elements by default', () => {
@Component({template: '<some-element [someUnknownProp]="true"></some-element>'}) @Component({template: '<some-element [someUnknownProp]="true"></some-element>'})
class ComponentUsingInvalidProperty { class ComponentUsingInvalidProperty {