test(ivy): enable ivy tests for platform-browser (#27460)
PR Close #27460
This commit is contained in:
parent
b25f06ee7c
commit
c07afd9db1
|
@ -22,6 +22,7 @@ ts_library(
|
||||||
"//packages/platform-browser-dynamic",
|
"//packages/platform-browser-dynamic",
|
||||||
"//packages/platform-browser/animations",
|
"//packages/platform-browser/animations",
|
||||||
"//packages/platform-browser/testing",
|
"//packages/platform-browser/testing",
|
||||||
|
"//packages/private/testing",
|
||||||
"@rxjs",
|
"@rxjs",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -29,9 +30,6 @@ ts_library(
|
||||||
jasmine_node_test(
|
jasmine_node_test(
|
||||||
name = "test",
|
name = "test",
|
||||||
bootstrap = ["angular/tools/testing/init_node_spec.js"],
|
bootstrap = ["angular/tools/testing/init_node_spec.js"],
|
||||||
tags = [
|
|
||||||
"fixme-ivy-aot",
|
|
||||||
],
|
|
||||||
deps = [
|
deps = [
|
||||||
":test_lib",
|
":test_lib",
|
||||||
"//tools/testing:node",
|
"//tools/testing:node",
|
||||||
|
@ -43,9 +41,6 @@ ts_web_test_suite(
|
||||||
static_files = [
|
static_files = [
|
||||||
":static_assets/test.html",
|
":static_assets/test.html",
|
||||||
],
|
],
|
||||||
tags = [
|
|
||||||
"fixme-ivy-aot",
|
|
||||||
],
|
|
||||||
deps = [
|
deps = [
|
||||||
":test_lib",
|
":test_lib",
|
||||||
],
|
],
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||||
import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';
|
import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';
|
||||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
|
import {fixmeIvy} from '@angular/private/testing';
|
||||||
|
|
||||||
@Component({selector: 'non-existent', template: ''})
|
@Component({selector: 'non-existent', template: ''})
|
||||||
class NonExistentComp {
|
class NonExistentComp {
|
||||||
|
@ -159,17 +160,18 @@ function bootstrap(
|
||||||
|
|
||||||
afterEach(destroyPlatform);
|
afterEach(destroyPlatform);
|
||||||
|
|
||||||
it('should throw if bootstrapped Directive is not a Component',
|
fixmeIvy('unknown') &&
|
||||||
inject([AsyncTestCompleter], (done: AsyncTestCompleter) => {
|
it('should throw if bootstrapped Directive is not a Component',
|
||||||
const logger = new MockConsole();
|
inject([AsyncTestCompleter], (done: AsyncTestCompleter) => {
|
||||||
const errorHandler = new ErrorHandler();
|
const logger = new MockConsole();
|
||||||
(errorHandler as any)._console = logger as any;
|
const errorHandler = new ErrorHandler();
|
||||||
expect(
|
(errorHandler as any)._console = logger as any;
|
||||||
() => bootstrap(
|
expect(
|
||||||
HelloRootDirectiveIsNotCmp, [{provide: ErrorHandler, useValue: errorHandler}]))
|
() => bootstrap(
|
||||||
.toThrowError(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`);
|
HelloRootDirectiveIsNotCmp, [{provide: ErrorHandler, useValue: errorHandler}]))
|
||||||
done.done();
|
.toThrowError(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`);
|
||||||
}));
|
done.done();
|
||||||
|
}));
|
||||||
|
|
||||||
it('should throw if no element is found',
|
it('should throw if no element is found',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
|
@ -186,40 +188,42 @@ function bootstrap(
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should throw if no provider', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
fixmeIvy('unknown') &&
|
||||||
const logger = new MockConsole();
|
it('should throw if no provider',
|
||||||
const errorHandler = new ErrorHandler();
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
(errorHandler as any)._console = logger as any;
|
const logger = new MockConsole();
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
|
(errorHandler as any)._console = logger as any;
|
||||||
|
|
||||||
class IDontExist {}
|
class IDontExist {}
|
||||||
|
|
||||||
@Component({selector: 'cmp', template: 'Cmp'})
|
@Component({selector: 'cmp', template: 'Cmp'})
|
||||||
class CustomCmp {
|
class CustomCmp {
|
||||||
constructor(iDontExist: IDontExist) {}
|
constructor(iDontExist: IDontExist) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'hello-app',
|
selector: 'hello-app',
|
||||||
template: '<cmp></cmp>',
|
template: '<cmp></cmp>',
|
||||||
})
|
})
|
||||||
class RootCmp {
|
class RootCmp {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NgModule({declarations: [CustomCmp], exports: [CustomCmp]})
|
@NgModule({declarations: [CustomCmp], exports: [CustomCmp]})
|
||||||
class CustomModule {
|
class CustomModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap(RootCmp, [{provide: ErrorHandler, useValue: errorHandler}], [], [
|
bootstrap(RootCmp, [{provide: ErrorHandler, useValue: errorHandler}], [], [
|
||||||
CustomModule
|
CustomModule
|
||||||
]).then(null, (e: Error) => {
|
]).then(null, (e: Error) => {
|
||||||
expect(e.message).toContain(
|
expect(e.message).toContain(
|
||||||
'StaticInjectorError(TestModule)[CustomCmp -> IDontExist]: \n' +
|
'StaticInjectorError(TestModule)[CustomCmp -> IDontExist]: \n' +
|
||||||
' StaticInjectorError(Platform: core)[CustomCmp -> IDontExist]: \n' +
|
' StaticInjectorError(Platform: core)[CustomCmp -> IDontExist]: \n' +
|
||||||
' NullInjectorError: No provider for IDontExist!');
|
' NullInjectorError: No provider for IDontExist!');
|
||||||
async.done();
|
async.done();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (getDOM().supportsDOMEvents()) {
|
if (getDOM().supportsDOMEvents()) {
|
||||||
it('should forward the error to promise when bootstrap fails',
|
it('should forward the error to promise when bootstrap fails',
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
import {Component, Renderer2, ViewEncapsulation} from '@angular/core';
|
import {Component, Renderer2, ViewEncapsulation} from '@angular/core';
|
||||||
import {TestBed} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
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 {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
import {NAMESPACE_URIS} from '../../src/dom/dom_renderer';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('DefaultDomRendererV2', () => {
|
describe('DefaultDomRendererV2', () => {
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
|
|
||||||
import {SecurityContext} from '@angular/core';
|
import {SecurityContext} from '@angular/core';
|
||||||
import * as t from '@angular/core/testing/src/testing_internal';
|
import * as t from '@angular/core/testing/src/testing_internal';
|
||||||
|
import {DomSanitizerImpl} from '@angular/platform-browser/src/security/dom_sanitization_service';
|
||||||
import {DomSanitizerImpl} from '../../src/security/dom_sanitization_service';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
t.describe('DOM Sanitization Service', () => {
|
t.describe('DOM Sanitization Service', () => {
|
||||||
|
|
|
@ -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 {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';
|
||||||
|
|
||||||
// Services, and components for the tests.
|
// Services, and components for the tests.
|
||||||
|
|
||||||
|
@ -250,7 +251,7 @@ class CompWithUrlTemplate {
|
||||||
expect(compFixture.componentInstance).toBeAnInstanceOf(CompUsingModuleDirectiveAndPipe);
|
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 compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe);
|
||||||
const el = compFixture.debugElement;
|
const el = compFixture.debugElement;
|
||||||
|
|
||||||
|
@ -287,13 +288,14 @@ class CompWithUrlTemplate {
|
||||||
expect(service.value).toEqual('real value');
|
expect(service.value).toEqual('real value');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should use set up directives and pipes', withModule(moduleConfig, () => {
|
fixmeIvy('unknown') &&
|
||||||
const compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe);
|
it('should use set up directives and pipes', withModule(moduleConfig, () => {
|
||||||
const el = compFixture.debugElement;
|
const compFixture = TestBed.createComponent(CompUsingModuleDirectiveAndPipe);
|
||||||
|
const el = compFixture.debugElement;
|
||||||
|
|
||||||
compFixture.detectChanges();
|
compFixture.detectChanges();
|
||||||
expect(el.children[0].properties['title']).toBe('transformed someValue');
|
expect(el.children[0].properties['title']).toBe('transformed someValue');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should use set up library modules',
|
it('should use set up library modules',
|
||||||
withModule(moduleConfig).inject([SomeLibModule], (libModule: SomeLibModule) => {
|
withModule(moduleConfig).inject([SomeLibModule], (libModule: SomeLibModule) => {
|
||||||
|
@ -307,7 +309,7 @@ class CompWithUrlTemplate {
|
||||||
TestBed.compileComponents();
|
TestBed.compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
isBrowser &&
|
fixmeIvy('unknown') && 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);
|
||||||
|
@ -368,7 +370,7 @@ class CompWithUrlTemplate {
|
||||||
.overrideDirective(
|
.overrideDirective(
|
||||||
SomeDirective, {set: {selector: '[someDir]', host: {'[title]': 'someProp'}}});
|
SomeDirective, {set: {selector: '[someDir]', host: {'[title]': 'someProp'}}});
|
||||||
});
|
});
|
||||||
it('should work', () => {
|
fixmeIvy('unknown') && 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');
|
||||||
|
@ -383,7 +385,7 @@ class CompWithUrlTemplate {
|
||||||
.overridePipe(SomePipe, {set: {name: 'somePipe'}})
|
.overridePipe(SomePipe, {set: {name: 'somePipe'}})
|
||||||
.overridePipe(SomePipe, {add: {pure: false}});
|
.overridePipe(SomePipe, {add: {pure: false}});
|
||||||
});
|
});
|
||||||
it('should work', () => {
|
fixmeIvy('unknown') && 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');
|
||||||
|
@ -453,7 +455,7 @@ class CompWithUrlTemplate {
|
||||||
expect(TestBed.get('a')).toBe('mockA: depValue');
|
expect(TestBed.get('a')).toBe('mockA: depValue');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support SkipSelf', () => {
|
fixmeIvy('unknown') && it('should support SkipSelf', () => {
|
||||||
@NgModule({
|
@NgModule({
|
||||||
providers: [
|
providers: [
|
||||||
{provide: 'a', useValue: 'aValue'},
|
{provide: 'a', useValue: 'aValue'},
|
||||||
|
@ -493,25 +495,26 @@ class CompWithUrlTemplate {
|
||||||
expect(someModule).toBeAnInstanceOf(SomeModule);
|
expect(someModule).toBeAnInstanceOf(SomeModule);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should keep imported NgModules lazy with deprecatedOverrideProvider', () => {
|
fixmeIvy('unknown') &&
|
||||||
let someModule: SomeModule|undefined;
|
it('should keep imported NgModules lazy with deprecatedOverrideProvider', () => {
|
||||||
|
let someModule: SomeModule|undefined;
|
||||||
|
|
||||||
@NgModule()
|
@NgModule()
|
||||||
class SomeModule {
|
class SomeModule {
|
||||||
constructor() { someModule = this; }
|
constructor() { someModule = this; }
|
||||||
}
|
}
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
{provide: 'a', useValue: 'aValue'},
|
{provide: 'a', useValue: 'aValue'},
|
||||||
],
|
],
|
||||||
imports: [SomeModule]
|
imports: [SomeModule]
|
||||||
});
|
});
|
||||||
TestBed.deprecatedOverrideProvider('a', {useValue: 'mockValue'});
|
TestBed.deprecatedOverrideProvider('a', {useValue: 'mockValue'});
|
||||||
|
|
||||||
expect(TestBed.get('a')).toBe('mockValue');
|
expect(TestBed.get('a')).toBe('mockValue');
|
||||||
expect(someModule).toBeUndefined();
|
expect(someModule).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('injecting eager providers into an eager overwritten provider', () => {
|
describe('injecting eager providers into an eager overwritten provider', () => {
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
@ -544,7 +547,7 @@ class CompWithUrlTemplate {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('in Components', () => {
|
describe('in Components', () => {
|
||||||
it('should support useValue', () => {
|
fixmeIvy('unknown') && it('should support useValue', () => {
|
||||||
@Component({
|
@Component({
|
||||||
template: '',
|
template: '',
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -561,7 +564,7 @@ class CompWithUrlTemplate {
|
||||||
expect(ctx.debugElement.injector.get('a')).toBe('mockValue');
|
expect(ctx.debugElement.injector.get('a')).toBe('mockValue');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support useFactory', () => {
|
fixmeIvy('unknown') && it('should support useFactory', () => {
|
||||||
@Component({
|
@Component({
|
||||||
template: '',
|
template: '',
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -580,7 +583,7 @@ class CompWithUrlTemplate {
|
||||||
expect(ctx.debugElement.injector.get('a')).toBe('mockA: depValue');
|
expect(ctx.debugElement.injector.get('a')).toBe('mockA: depValue');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support @Optional without matches', () => {
|
fixmeIvy('unknown') && it('should support @Optional without matches', () => {
|
||||||
@Component({
|
@Component({
|
||||||
template: '',
|
template: '',
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -598,7 +601,7 @@ class CompWithUrlTemplate {
|
||||||
expect(ctx.debugElement.injector.get('a')).toBe('mockA: null');
|
expect(ctx.debugElement.injector.get('a')).toBe('mockA: null');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support Optional with matches', () => {
|
fixmeIvy('unknown') && it('should support Optional with matches', () => {
|
||||||
@Component({
|
@Component({
|
||||||
template: '',
|
template: '',
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -617,7 +620,7 @@ class CompWithUrlTemplate {
|
||||||
expect(ctx.debugElement.injector.get('a')).toBe('mockA: depValue');
|
expect(ctx.debugElement.injector.get('a')).toBe('mockA: depValue');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support SkipSelf', () => {
|
fixmeIvy('unknown') && it('should support SkipSelf', () => {
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[myDir]',
|
selector: '[myDir]',
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -644,7 +647,7 @@ class CompWithUrlTemplate {
|
||||||
expect(ctx.debugElement.children[0].injector.get('a')).toBe('mockA: parentDepValue');
|
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({
|
@Directive({
|
||||||
selector: '[myDir1]',
|
selector: '[myDir1]',
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -689,24 +692,26 @@ class CompWithUrlTemplate {
|
||||||
constructor(@Inject('a') a: any, @Inject('b') b: any) {}
|
constructor(@Inject('a') a: any, @Inject('b') b: any) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should inject providers that were declared before it', () => {
|
fixmeIvy('unknown') &&
|
||||||
TestBed.overrideProvider(
|
it('should inject providers that were declared before it', () => {
|
||||||
'b', {useFactory: (a: string) => `mockB: ${a}`, deps: ['a']});
|
TestBed.overrideProvider(
|
||||||
const ctx =
|
'b', {useFactory: (a: string) => `mockB: ${a}`, deps: ['a']});
|
||||||
TestBed.configureTestingModule({declarations: [MyComp]}).createComponent(MyComp);
|
const ctx = TestBed.configureTestingModule({declarations: [MyComp]})
|
||||||
|
.createComponent(MyComp);
|
||||||
|
|
||||||
expect(ctx.debugElement.injector.get('b')).toBe('mockB: aValue');
|
expect(ctx.debugElement.injector.get('b')).toBe('mockB: aValue');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inject providers that were declared after it', () => {
|
fixmeIvy('unknown') &&
|
||||||
TestBed.overrideProvider(
|
it('should inject providers that were declared after it', () => {
|
||||||
'a', {useFactory: (b: string) => `mockA: ${b}`, deps: ['b']});
|
TestBed.overrideProvider(
|
||||||
const ctx =
|
'a', {useFactory: (b: string) => `mockA: ${b}`, deps: ['b']});
|
||||||
TestBed.configureTestingModule({declarations: [MyComp]}).createComponent(MyComp);
|
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', () => {
|
it('should reset overrides when the testing modules is resetted', () => {
|
||||||
|
@ -718,35 +723,36 @@ class CompWithUrlTemplate {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('overrideTemplateUsingTestingModule', () => {
|
describe('overrideTemplateUsingTestingModule', () => {
|
||||||
it('should compile the template in the context of the testing module', () => {
|
fixmeIvy('unknown') &&
|
||||||
@Component({selector: 'comp', template: 'a'})
|
it('should compile the template in the context of the testing module', () => {
|
||||||
class MyComponent {
|
@Component({selector: 'comp', template: 'a'})
|
||||||
prop = 'some prop';
|
class MyComponent {
|
||||||
}
|
prop = 'some prop';
|
||||||
|
}
|
||||||
|
|
||||||
let testDir: TestDir|undefined;
|
let testDir: TestDir|undefined;
|
||||||
|
|
||||||
@Directive({selector: '[test]'})
|
@Directive({selector: '[test]'})
|
||||||
class TestDir {
|
class TestDir {
|
||||||
constructor() { testDir = this; }
|
constructor() { testDir = this; }
|
||||||
|
|
||||||
// TODO(issue/24571): remove '!'.
|
// TODO(issue/24571): remove '!'.
|
||||||
@Input('test')
|
@Input('test')
|
||||||
test !: string;
|
test !: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestBed.overrideTemplateUsingTestingModule(
|
TestBed.overrideTemplateUsingTestingModule(
|
||||||
MyComponent, '<div [test]="prop">Hello world!</div>');
|
MyComponent, '<div [test]="prop">Hello world!</div>');
|
||||||
|
|
||||||
const fixture = TestBed.configureTestingModule({declarations: [MyComponent, TestDir]})
|
const fixture = TestBed.configureTestingModule({declarations: [MyComponent, TestDir]})
|
||||||
.createComponent(MyComponent);
|
.createComponent(MyComponent);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.nativeElement).toHaveText('Hello world!');
|
expect(fixture.nativeElement).toHaveText('Hello world!');
|
||||||
expect(testDir).toBeAnInstanceOf(TestDir);
|
expect(testDir).toBeAnInstanceOf(TestDir);
|
||||||
expect(testDir !.test).toBe('some prop');
|
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'})
|
@Component({selector: 'comp', template: 'a'})
|
||||||
class MyComponent {
|
class MyComponent {
|
||||||
}
|
}
|
||||||
|
@ -758,18 +764,19 @@ class CompWithUrlTemplate {
|
||||||
/Cannot override template when the test module has already been instantiated/);
|
/Cannot override template when the test module has already been instantiated/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reset overrides when the testing module is resetted', () => {
|
fixmeIvy('unknown') &&
|
||||||
@Component({selector: 'comp', template: 'a'})
|
it('should reset overrides when the testing module is resetted', () => {
|
||||||
class MyComponent {
|
@Component({selector: 'comp', template: 'a'})
|
||||||
}
|
class MyComponent {
|
||||||
|
}
|
||||||
|
|
||||||
TestBed.overrideTemplateUsingTestingModule(MyComponent, 'b');
|
TestBed.overrideTemplateUsingTestingModule(MyComponent, 'b');
|
||||||
|
|
||||||
const fixture = TestBed.resetTestingModule()
|
const fixture = TestBed.resetTestingModule()
|
||||||
.configureTestingModule({declarations: [MyComponent]})
|
.configureTestingModule({declarations: [MyComponent]})
|
||||||
.createComponent(MyComponent);
|
.createComponent(MyComponent);
|
||||||
expect(fixture.nativeElement).toHaveText('a');
|
expect(fixture.nativeElement).toHaveText('a');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setting up the compiler', () => {
|
describe('setting up the compiler', () => {
|
||||||
|
@ -783,27 +790,28 @@ class CompWithUrlTemplate {
|
||||||
{providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]});
|
{providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use set up providers', fakeAsync(() => {
|
fixmeIvy('unknown') && it('should use set up providers', fakeAsync(() => {
|
||||||
TestBed.compileComponents();
|
TestBed.compileComponents();
|
||||||
tick();
|
tick();
|
||||||
const compFixture = TestBed.createComponent(CompWithUrlTemplate);
|
const compFixture =
|
||||||
expect(compFixture.nativeElement).toHaveText('Hello world!');
|
TestBed.createComponent(CompWithUrlTemplate);
|
||||||
}));
|
expect(compFixture.nativeElement).toHaveText('Hello world!');
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('useJit true', () => {
|
describe('useJit true', () => {
|
||||||
beforeEach(() => TestBed.configureCompiler({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) => {
|
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}));
|
||||||
it('should set the value into CompilerConfig',
|
fixmeIvy('unknown') && 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);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -892,40 +900,43 @@ class CompWithUrlTemplate {
|
||||||
{providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]});
|
{providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report an error for declared components with templateUrl which never call TestBed.compileComponents',
|
fixmeIvy('unknown') &&
|
||||||
() => {
|
it('should report an error for declared components with templateUrl which never call TestBed.compileComponents',
|
||||||
const itPromise = patchJasmineIt();
|
() => {
|
||||||
|
const itPromise = patchJasmineIt();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
() =>
|
() =>
|
||||||
it('should fail', withModule(
|
it('should fail', withModule(
|
||||||
{declarations: [CompWithUrlTemplate]},
|
{declarations: [CompWithUrlTemplate]},
|
||||||
() => TestBed.createComponent(CompWithUrlTemplate))))
|
() => TestBed.createComponent(CompWithUrlTemplate))))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
`This test module uses the component ${stringify(CompWithUrlTemplate)} which is using a "templateUrl" or "styleUrls", but they were never compiled. ` +
|
`This test module uses the component ${stringify(CompWithUrlTemplate)} which is using a "templateUrl" or "styleUrls", but they were never compiled. ` +
|
||||||
`Please call "TestBed.compileComponents" before your test.`);
|
`Please call "TestBed.compileComponents" before your test.`);
|
||||||
|
|
||||||
restoreJasmineIt();
|
restoreJasmineIt();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should error on unknown bound properties on custom elements by default', () => {
|
fixmeIvy('unknown') &&
|
||||||
@Component({template: '<some-element [someUnknownProp]="true"></some-element>'})
|
it('should error on unknown bound properties on custom elements by default', () => {
|
||||||
class ComponentUsingInvalidProperty {
|
@Component({template: '<some-element [someUnknownProp]="true"></some-element>'})
|
||||||
}
|
class ComponentUsingInvalidProperty {
|
||||||
|
}
|
||||||
|
|
||||||
const itPromise = patchJasmineIt();
|
const itPromise = patchJasmineIt();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
() => it(
|
() =>
|
||||||
'should fail', withModule(
|
it('should fail',
|
||||||
{declarations: [ComponentUsingInvalidProperty]},
|
withModule(
|
||||||
() => TestBed.createComponent(ComponentUsingInvalidProperty))))
|
{declarations: [ComponentUsingInvalidProperty]},
|
||||||
.toThrowError(/Can't bind to 'someUnknownProp'/);
|
() => TestBed.createComponent(ComponentUsingInvalidProperty))))
|
||||||
|
.toThrowError(/Can't bind to 'someUnknownProp'/);
|
||||||
|
|
||||||
restoreJasmineIt();
|
restoreJasmineIt();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('creating components', () => {
|
describe('creating components', () => {
|
||||||
|
|
Loading…
Reference in New Issue