From 9062b391a2bbd84eed1573f2ddc322bc4aabad82 Mon Sep 17 00:00:00 2001 From: Olivier Combe Date: Tue, 4 Dec 2018 17:51:34 +0100 Subject: [PATCH] test(ivy): root cause analysis for platform-browser (#27460) PR Close #27460 --- .../test/browser/bootstrap_spec.ts | 4 +- .../test/testing_public_spec.ts | 398 +++++++++--------- 2 files changed, 212 insertions(+), 190 deletions(-) diff --git a/packages/platform-browser/test/browser/bootstrap_spec.ts b/packages/platform-browser/test/browser/bootstrap_spec.ts index b021959f32..56f7ec5356 100644 --- a/packages/platform-browser/test/browser/bootstrap_spec.ts +++ b/packages/platform-browser/test/browser/bootstrap_spec.ts @@ -160,7 +160,7 @@ function bootstrap( afterEach(destroyPlatform); - fixmeIvy('unknown') && + fixmeIvy('FW-553: TestBed is unaware of async compilation') && it('should throw if bootstrapped Directive is not a Component', inject([AsyncTestCompleter], (done: AsyncTestCompleter) => { 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', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { const logger = new MockConsole(); diff --git a/packages/platform-browser/test/testing_public_spec.ts b/packages/platform-browser/test/testing_public_spec.ts index 593329a33e..3546181837 100644 --- a/packages/platform-browser/test/testing_public_spec.ts +++ b/packages/platform-browser/test/testing_public_spec.ts @@ -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 {TestBed, async, fakeAsync, getTestBed, inject, tick, withModule} from '@angular/core/testing'; 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. @@ -251,13 +251,14 @@ class CompWithUrlTemplate { expect(compFixture.componentInstance).toBeAnInstanceOf(CompUsingModuleDirectiveAndPipe); }); - fixmeIvy('unknown') && it('should use set up directives and pipes', () => { - const compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe); - const el = compFixture.debugElement; + 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 el = compFixture.debugElement; - compFixture.detectChanges(); - expect(el.children[0].properties['title']).toBe('transformed someValue'); - }); + compFixture.detectChanges(); + expect(el.children[0].properties['title']).toBe('transformed someValue'); + }); it('should use set up imported modules', inject([SomeLibModule], (libModule: SomeLibModule) => { @@ -288,7 +289,7 @@ class CompWithUrlTemplate { 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, () => { const compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe); const el = compFixture.debugElement; @@ -309,7 +310,7 @@ class CompWithUrlTemplate { 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', () => { const fixture = TestBed.createComponent(CompWithUrlTemplate); @@ -370,11 +371,12 @@ class CompWithUrlTemplate { .overrideDirective( SomeDirective, {set: {selector: '[someDir]', host: {'[title]': 'someProp'}}}); }); - fixmeIvy('unknown') && it('should work', () => { - const compFixture = TestBed.createComponent(SomeComponent); - compFixture.detectChanges(); - expect(compFixture.debugElement.children[0].properties['title']).toEqual('hello'); - }); + fixmeIvy('FW-681: not possible to retrieve host property bindings from TView') && + it('should work', () => { + const compFixture = TestBed.createComponent(SomeComponent); + compFixture.detectChanges(); + expect(compFixture.debugElement.children[0].properties['title']).toEqual('hello'); + }); }); describe('pipe', () => { @@ -385,11 +387,12 @@ class CompWithUrlTemplate { .overridePipe(SomePipe, {set: {name: 'somePipe'}}) .overridePipe(SomePipe, {add: {pure: false}}); }); - fixmeIvy('unknown') && it('should work', () => { - const compFixture = TestBed.createComponent(SomeComponent); - compFixture.detectChanges(); - expect(compFixture.nativeElement).toHaveText('transformed hello'); - }); + fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') && + it('should work', () => { + const compFixture = TestBed.createComponent(SomeComponent); + compFixture.detectChanges(); + expect(compFixture.nativeElement).toHaveText('transformed hello'); + }); }); describe('template', () => { @@ -455,25 +458,28 @@ class CompWithUrlTemplate { expect(TestBed.get('a')).toBe('mockA: depValue'); }); - fixmeIvy('unknown') && it('should support SkipSelf', () => { - @NgModule({ - providers: [ - {provide: 'a', useValue: 'aValue'}, - {provide: 'dep', useValue: 'depValue'}, - ] - }) - class MyModule { - } + fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') && + it('should support SkipSelf', () => { + @NgModule({ + providers: [ + {provide: 'a', useValue: 'aValue'}, + {provide: 'dep', useValue: 'depValue'}, + ] + }) + class MyModule { + } - TestBed.overrideProvider( - 'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new SkipSelf(), 'dep']]}); - TestBed.configureTestingModule( - {providers: [{provide: 'dep', useValue: 'parentDepValue'}]}); + TestBed.overrideProvider( + 'a', + {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new SkipSelf(), 'dep']]}); + TestBed.configureTestingModule( + {providers: [{provide: 'dep', useValue: 'parentDepValue'}]}); - const compiler = TestBed.get(Compiler) as Compiler; - const modFactory = compiler.compileModuleSync(MyModule); - expect(modFactory.create(getTestBed()).injector.get('a')).toBe('mockA: parentDepValue'); - }); + const compiler = TestBed.get(Compiler) as Compiler; + const modFactory = compiler.compileModuleSync(MyModule); + expect(modFactory.create(getTestBed()).injector.get('a')) + .toBe('mockA: parentDepValue'); + }); it('should keep imported NgModules eager', () => { let someModule: SomeModule|undefined; @@ -495,7 +501,7 @@ class CompWithUrlTemplate { expect(someModule).toBeAnInstanceOf(SomeModule); }); - fixmeIvy('unknown') && + obsoleteInIvy(`deprecated method, won't be reimplemented for Render3`) && it('should keep imported NgModules lazy with deprecatedOverrideProvider', () => { let someModule: SomeModule|undefined; @@ -547,137 +553,147 @@ class CompWithUrlTemplate { }); describe('in Components', () => { - fixmeIvy('unknown') && it('should support useValue', () => { - @Component({ - template: '', - providers: [ - {provide: 'a', useValue: 'aValue'}, - ] - }) - class MComp { - } + fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') && + it('should support useValue', () => { + @Component({ + template: '', + providers: [ + {provide: 'a', useValue: 'aValue'}, + ] + }) + class MComp { + } - TestBed.overrideProvider('a', {useValue: 'mockValue'}); - const ctx = - TestBed.configureTestingModule({declarations: [MComp]}).createComponent(MComp); + TestBed.overrideProvider('a', {useValue: 'mockValue'}); + const ctx = + TestBed.configureTestingModule({declarations: [MComp]}).createComponent(MComp); - expect(ctx.debugElement.injector.get('a')).toBe('mockValue'); - }); + expect(ctx.debugElement.injector.get('a')).toBe('mockValue'); + }); - fixmeIvy('unknown') && it('should support useFactory', () => { - @Component({ - template: '', - providers: [ - {provide: 'dep', useValue: 'depValue'}, - {provide: 'a', useValue: 'aValue'}, - ] - }) - class MyComp { - } + fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') && + it('should support useFactory', () => { + @Component({ + template: '', + providers: [ + {provide: 'dep', useValue: 'depValue'}, + {provide: 'a', useValue: 'aValue'}, + ] + }) + class MyComp { + } - TestBed.overrideProvider( - 'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: ['dep']}); - const ctx = - TestBed.configureTestingModule({declarations: [MyComp]}).createComponent(MyComp); + TestBed.overrideProvider( + 'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: ['dep']}); + 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 @Optional without matches', () => { - @Component({ - template: '', - providers: [ - {provide: 'a', useValue: 'aValue'}, - ] - }) - class MyComp { - } + fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') && + it('should support @Optional without matches', () => { + @Component({ + template: '', + providers: [ + {provide: 'a', useValue: 'aValue'}, + ] + }) + class MyComp { + } - TestBed.overrideProvider( - 'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new Optional(), 'dep']]}); - const ctx = - TestBed.configureTestingModule({declarations: [MyComp]}).createComponent(MyComp); + TestBed.overrideProvider( + 'a', + {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new Optional(), 'dep']]}); + 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', () => { - @Component({ - template: '', - providers: [ - {provide: 'dep', useValue: 'depValue'}, - {provide: 'a', useValue: 'aValue'}, - ] - }) - class MyComp { - } + fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') && + it('should support Optional with matches', () => { + @Component({ + template: '', + providers: [ + {provide: 'dep', useValue: 'depValue'}, + {provide: 'a', useValue: 'aValue'}, + ] + }) + class MyComp { + } - TestBed.overrideProvider( - 'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new Optional(), 'dep']]}); - const ctx = - TestBed.configureTestingModule({declarations: [MyComp]}).createComponent(MyComp); + TestBed.overrideProvider( + 'a', + {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new Optional(), 'dep']]}); + 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', () => { - @Directive({ - selector: '[myDir]', - providers: [ - {provide: 'a', useValue: 'aValue'}, - {provide: 'dep', useValue: 'depValue'}, - ] - }) - class MyDir { - } + fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') && + it('should support SkipSelf', () => { + @Directive({ + selector: '[myDir]', + providers: [ + {provide: 'a', useValue: 'aValue'}, + {provide: 'dep', useValue: 'depValue'}, + ] + }) + class MyDir { + } - @Component({ - template: '
', - providers: [ - {provide: 'dep', useValue: 'parentDepValue'}, - ] - }) - class MyComp { - } + @Component({ + template: '
', + providers: [ + {provide: 'dep', useValue: 'parentDepValue'}, + ] + }) + class MyComp { + } - TestBed.overrideProvider( - 'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new SkipSelf(), 'dep']]}); - const ctx = TestBed.configureTestingModule({declarations: [MyComp, MyDir]}) - .createComponent(MyComp); - expect(ctx.debugElement.children[0].injector.get('a')).toBe('mockA: parentDepValue'); - }); + TestBed.overrideProvider( + 'a', + {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new SkipSelf(), 'dep']]}); + const ctx = TestBed.configureTestingModule({declarations: [MyComp, MyDir]}) + .createComponent(MyComp); + expect(ctx.debugElement.children[0].injector.get('a')) + .toBe('mockA: parentDepValue'); + }); - fixmeIvy('unknown') && it('should support multiple providers in a template', () => { - @Directive({ - selector: '[myDir1]', - providers: [ - {provide: 'a', useValue: 'aValue1'}, - ] - }) - class MyDir1 { - } + fixmeIvy('FW-788: Support metadata override in TestBed (for AOT-compiled components)') && + it('should support multiple providers in a template', () => { + @Directive({ + selector: '[myDir1]', + providers: [ + {provide: 'a', useValue: 'aValue1'}, + ] + }) + class MyDir1 { + } - @Directive({ - selector: '[myDir2]', - providers: [ - {provide: 'a', useValue: 'aValue2'}, - ] - }) - class MyDir2 { - } + @Directive({ + selector: '[myDir2]', + providers: [ + {provide: 'a', useValue: 'aValue2'}, + ] + }) + class MyDir2 { + } - @Component({ - template: '
', - }) - class MyComp { - } + @Component({ + template: '
', + }) + class MyComp { + } - TestBed.overrideProvider('a', {useValue: 'mockA'}); - const ctx = TestBed.configureTestingModule({declarations: [MyComp, MyDir1, MyDir2]}) - .createComponent(MyComp); - expect(ctx.debugElement.children[0].injector.get('a')).toBe('mockA'); - expect(ctx.debugElement.children[1].injector.get('a')).toBe('mockA'); - }); + TestBed.overrideProvider('a', {useValue: 'mockA'}); + const ctx = TestBed.configureTestingModule({declarations: [MyComp, MyDir1, MyDir2]}) + .createComponent(MyComp); + expect(ctx.debugElement.children[0].injector.get('a')).toBe('mockA'); + expect(ctx.debugElement.children[1].injector.get('a')).toBe('mockA'); + }); describe('injecting eager providers into an eager overwritten provider', () => { @Component({ @@ -692,7 +708,8 @@ class CompWithUrlTemplate { 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', () => { TestBed.overrideProvider( 'b', {useFactory: (a: string) => `mockB: ${a}`, deps: ['a']}); @@ -702,16 +719,17 @@ class CompWithUrlTemplate { expect(ctx.debugElement.injector.get('b')).toBe('mockB: aValue'); }); - fixmeIvy('unknown') && - it('should inject providers that were declared after it', () => { - TestBed.overrideProvider( - 'a', {useFactory: (b: string) => `mockA: ${b}`, deps: ['b']}); - const ctx = TestBed.configureTestingModule({declarations: [MyComp]}) - .createComponent(MyComp); + fixmeIvy( + 'FW-788: Support metadata override in TestBed (for AOT-compiled components)') && + it('should inject providers that were declared after it', () => { + TestBed.overrideProvider( + 'a', {useFactory: (b: string) => `mockA: ${b}`, deps: ['b']}); + const ctx = TestBed.configureTestingModule({declarations: [MyComp]}) + .createComponent(MyComp); - expect(ctx.debugElement.injector.get('a')).toBe('mockA: bValue'); - }); - }); + expect(ctx.debugElement.injector.get('a')).toBe('mockA: bValue'); + }); + }); }); it('should reset overrides when the testing modules is resetted', () => { @@ -723,7 +741,7 @@ class CompWithUrlTemplate { }); 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', () => { @Component({selector: 'comp', template: 'a'}) class MyComponent { @@ -752,19 +770,20 @@ class CompWithUrlTemplate { expect(testDir !.test).toBe('some prop'); }); - fixmeIvy('unknown') && it('should throw if the TestBed is already created', () => { - @Component({selector: 'comp', template: 'a'}) - class MyComponent { - } + 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'}) + class MyComponent { + } - TestBed.get(Injector); + TestBed.get(Injector); - expect(() => TestBed.overrideTemplateUsingTestingModule(MyComponent, 'b')) - .toThrowError( - /Cannot override template when the test module has already been instantiated/); - }); + expect(() => TestBed.overrideTemplateUsingTestingModule(MyComponent, 'b')) + .toThrowError( + /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', () => { @Component({selector: 'comp', template: 'a'}) class MyComponent { @@ -790,28 +809,30 @@ class CompWithUrlTemplate { {providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]}); }); - fixmeIvy('unknown') && it('should use set up providers', fakeAsync(() => { - TestBed.compileComponents(); - tick(); - const compFixture = - TestBed.createComponent(CompWithUrlTemplate); - expect(compFixture.nativeElement).toHaveText('Hello world!'); - })); + fixmeIvy('FW-553: TestBed is unaware of async compilation') && + it('should use set up providers', fakeAsync(() => { + TestBed.compileComponents(); + tick(); + const compFixture = TestBed.createComponent(CompWithUrlTemplate); + expect(compFixture.nativeElement).toHaveText('Hello world!'); + })); }); describe('useJit true', () => { beforeEach(() => TestBed.configureCompiler({useJit: true})); - fixmeIvy('unknown') && it('should set the value into CompilerConfig', - inject([CompilerConfig], (config: CompilerConfig) => { - expect(config.useJit).toBe(true); - })); + obsoleteInIvy('the Render3 compiler JiT mode is not configurable') && + it('should set the value into CompilerConfig', + inject([CompilerConfig], (config: CompilerConfig) => { + expect(config.useJit).toBe(true); + })); }); describe('useJit false', () => { beforeEach(() => TestBed.configureCompiler({useJit: false})); - fixmeIvy('unknown') && it('should set the value into CompilerConfig', - inject([CompilerConfig], (config: CompilerConfig) => { - expect(config.useJit).toBe(false); - })); + obsoleteInIvy('the Render3 compiler JiT mode is not configurable') && + it('should set the value into CompilerConfig', + inject([CompilerConfig], (config: CompilerConfig) => { + expect(config.useJit).toBe(false); + })); }); }); }); @@ -900,7 +921,7 @@ class CompWithUrlTemplate { {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', () => { 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', () => { @Component({template: ''}) class ComponentUsingInvalidProperty {