test(ivy): enable ivy tests for platform-browser (#27460)

PR Close #27460
This commit is contained in:
Olivier Combe 2018-12-04 15:13:10 +01:00 committed by Igor Minar
parent b25f06ee7c
commit c07afd9db1
5 changed files with 179 additions and 170 deletions

View File

@ -22,6 +22,7 @@ ts_library(
"//packages/platform-browser-dynamic",
"//packages/platform-browser/animations",
"//packages/platform-browser/testing",
"//packages/private/testing",
"@rxjs",
],
)
@ -29,9 +30,6 @@ ts_library(
jasmine_node_test(
name = "test",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
tags = [
"fixme-ivy-aot",
],
deps = [
":test_lib",
"//tools/testing:node",
@ -43,9 +41,6 @@ ts_web_test_suite(
static_files = [
":static_assets/test.html",
],
tags = [
"fixme-ivy-aot",
],
deps = [
":test_lib",
],

View File

@ -18,6 +18,7 @@ import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {fixmeIvy} from '@angular/private/testing';
@Component({selector: 'non-existent', template: ''})
class NonExistentComp {
@ -159,6 +160,7 @@ function bootstrap(
afterEach(destroyPlatform);
fixmeIvy('unknown') &&
it('should throw if bootstrapped Directive is not a Component',
inject([AsyncTestCompleter], (done: AsyncTestCompleter) => {
const logger = new MockConsole();
@ -186,7 +188,9 @@ function bootstrap(
});
}));
it('should throw if no provider', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
fixmeIvy('unknown') &&
it('should throw if no provider',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const logger = new MockConsole();
const errorHandler = new ErrorHandler();
(errorHandler as any)._console = logger as any;

View File

@ -8,9 +8,9 @@
import {Component, Renderer2, ViewEncapsulation} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser/src/dom/debug/by';
import {NAMESPACE_URIS} from '@angular/platform-browser/src/dom/dom_renderer';
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {NAMESPACE_URIS} from '../../src/dom/dom_renderer';
{
describe('DefaultDomRendererV2', () => {

View File

@ -8,8 +8,7 @@
import {SecurityContext} from '@angular/core';
import * as t from '@angular/core/testing/src/testing_internal';
import {DomSanitizerImpl} from '../../src/security/dom_sanitization_service';
import {DomSanitizerImpl} from '@angular/platform-browser/src/security/dom_sanitization_service';
{
t.describe('DOM Sanitization Service', () => {

View File

@ -10,6 +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';
// Services, and components for the tests.
@ -250,7 +251,7 @@ class CompWithUrlTemplate {
expect(compFixture.componentInstance).toBeAnInstanceOf(CompUsingModuleDirectiveAndPipe);
});
it('should use set up directives and pipes', () => {
fixmeIvy('unknown') && it('should use set up directives and pipes', () => {
const compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe);
const el = compFixture.debugElement;
@ -287,6 +288,7 @@ class CompWithUrlTemplate {
expect(service.value).toEqual('real value');
}));
fixmeIvy('unknown') &&
it('should use set up directives and pipes', withModule(moduleConfig, () => {
const compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe);
const el = compFixture.debugElement;
@ -307,7 +309,7 @@ class CompWithUrlTemplate {
TestBed.compileComponents();
}));
isBrowser &&
fixmeIvy('unknown') && isBrowser &&
it('should allow to createSync components with templateUrl after explicit async compilation',
() => {
const fixture = TestBed.createComponent(CompWithUrlTemplate);
@ -368,7 +370,7 @@ class CompWithUrlTemplate {
.overrideDirective(
SomeDirective, {set: {selector: '[someDir]', host: {'[title]': 'someProp'}}});
});
it('should work', () => {
fixmeIvy('unknown') && it('should work', () => {
const compFixture = TestBed.createComponent(SomeComponent);
compFixture.detectChanges();
expect(compFixture.debugElement.children[0].properties['title']).toEqual('hello');
@ -383,7 +385,7 @@ class CompWithUrlTemplate {
.overridePipe(SomePipe, {set: {name: 'somePipe'}})
.overridePipe(SomePipe, {add: {pure: false}});
});
it('should work', () => {
fixmeIvy('unknown') && it('should work', () => {
const compFixture = TestBed.createComponent(SomeComponent);
compFixture.detectChanges();
expect(compFixture.nativeElement).toHaveText('transformed hello');
@ -453,7 +455,7 @@ class CompWithUrlTemplate {
expect(TestBed.get('a')).toBe('mockA: depValue');
});
it('should support SkipSelf', () => {
fixmeIvy('unknown') && it('should support SkipSelf', () => {
@NgModule({
providers: [
{provide: 'a', useValue: 'aValue'},
@ -493,6 +495,7 @@ class CompWithUrlTemplate {
expect(someModule).toBeAnInstanceOf(SomeModule);
});
fixmeIvy('unknown') &&
it('should keep imported NgModules lazy with deprecatedOverrideProvider', () => {
let someModule: SomeModule|undefined;
@ -544,7 +547,7 @@ class CompWithUrlTemplate {
});
describe('in Components', () => {
it('should support useValue', () => {
fixmeIvy('unknown') && it('should support useValue', () => {
@Component({
template: '',
providers: [
@ -561,7 +564,7 @@ class CompWithUrlTemplate {
expect(ctx.debugElement.injector.get('a')).toBe('mockValue');
});
it('should support useFactory', () => {
fixmeIvy('unknown') && it('should support useFactory', () => {
@Component({
template: '',
providers: [
@ -580,7 +583,7 @@ class CompWithUrlTemplate {
expect(ctx.debugElement.injector.get('a')).toBe('mockA: depValue');
});
it('should support @Optional without matches', () => {
fixmeIvy('unknown') && it('should support @Optional without matches', () => {
@Component({
template: '',
providers: [
@ -598,7 +601,7 @@ class CompWithUrlTemplate {
expect(ctx.debugElement.injector.get('a')).toBe('mockA: null');
});
it('should support Optional with matches', () => {
fixmeIvy('unknown') && it('should support Optional with matches', () => {
@Component({
template: '',
providers: [
@ -617,7 +620,7 @@ class CompWithUrlTemplate {
expect(ctx.debugElement.injector.get('a')).toBe('mockA: depValue');
});
it('should support SkipSelf', () => {
fixmeIvy('unknown') && it('should support SkipSelf', () => {
@Directive({
selector: '[myDir]',
providers: [
@ -644,7 +647,7 @@ class CompWithUrlTemplate {
expect(ctx.debugElement.children[0].injector.get('a')).toBe('mockA: parentDepValue');
});
it('should support multiple providers in a template', () => {
fixmeIvy('unknown') && it('should support multiple providers in a template', () => {
@Directive({
selector: '[myDir1]',
providers: [
@ -689,20 +692,22 @@ class CompWithUrlTemplate {
constructor(@Inject('a') a: any, @Inject('b') b: any) {}
}
fixmeIvy('unknown') &&
it('should inject providers that were declared before it', () => {
TestBed.overrideProvider(
'b', {useFactory: (a: string) => `mockB: ${a}`, deps: ['a']});
const ctx =
TestBed.configureTestingModule({declarations: [MyComp]}).createComponent(MyComp);
const ctx = TestBed.configureTestingModule({declarations: [MyComp]})
.createComponent(MyComp);
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);
const ctx = TestBed.configureTestingModule({declarations: [MyComp]})
.createComponent(MyComp);
expect(ctx.debugElement.injector.get('a')).toBe('mockA: bValue');
});
@ -718,6 +723,7 @@ class CompWithUrlTemplate {
});
describe('overrideTemplateUsingTestingModule', () => {
fixmeIvy('unknown') &&
it('should compile the template in the context of the testing module', () => {
@Component({selector: 'comp', template: 'a'})
class MyComponent {
@ -746,7 +752,7 @@ class CompWithUrlTemplate {
expect(testDir !.test).toBe('some prop');
});
it('should throw if the TestBed is already created', () => {
fixmeIvy('unknown') && it('should throw if the TestBed is already created', () => {
@Component({selector: 'comp', template: 'a'})
class MyComponent {
}
@ -758,6 +764,7 @@ class CompWithUrlTemplate {
/Cannot override template when the test module has already been instantiated/);
});
fixmeIvy('unknown') &&
it('should reset overrides when the testing module is resetted', () => {
@Component({selector: 'comp', template: 'a'})
class MyComponent {
@ -783,24 +790,25 @@ class CompWithUrlTemplate {
{providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]});
});
it('should use set up providers', fakeAsync(() => {
fixmeIvy('unknown') && it('should use set up providers', fakeAsync(() => {
TestBed.compileComponents();
tick();
const compFixture = TestBed.createComponent(CompWithUrlTemplate);
const compFixture =
TestBed.createComponent(CompWithUrlTemplate);
expect(compFixture.nativeElement).toHaveText('Hello world!');
}));
});
describe('useJit true', () => {
beforeEach(() => TestBed.configureCompiler({useJit: true}));
it('should set the value into CompilerConfig',
fixmeIvy('unknown') && it('should set the value into CompilerConfig',
inject([CompilerConfig], (config: CompilerConfig) => {
expect(config.useJit).toBe(true);
}));
});
describe('useJit false', () => {
beforeEach(() => TestBed.configureCompiler({useJit: false}));
it('should set the value into CompilerConfig',
fixmeIvy('unknown') && it('should set the value into CompilerConfig',
inject([CompilerConfig], (config: CompilerConfig) => {
expect(config.useJit).toBe(false);
}));
@ -892,6 +900,7 @@ class CompWithUrlTemplate {
{providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]});
});
fixmeIvy('unknown') &&
it('should report an error for declared components with templateUrl which never call TestBed.compileComponents',
() => {
const itPromise = patchJasmineIt();
@ -910,6 +919,7 @@ class CompWithUrlTemplate {
});
fixmeIvy('unknown') &&
it('should error on unknown bound properties on custom elements by default', () => {
@Component({template: '<some-element [someUnknownProp]="true"></some-element>'})
class ComponentUsingInvalidProperty {
@ -918,8 +928,9 @@ class CompWithUrlTemplate {
const itPromise = patchJasmineIt();
expect(
() => it(
'should fail', withModule(
() =>
it('should fail',
withModule(
{declarations: [ComponentUsingInvalidProperty]},
() => TestBed.createComponent(ComponentUsingInvalidProperty))))
.toThrowError(/Can't bind to 'someUnknownProp'/);