fix(core/testing compiler/testing): move TestComponentBuilder to core/testing (#9590)
TestComponentBuilder now lives in core/testing. compiler/testing contains a private OverridingTestComponentBuilder implementation which handles the private behavior we need to override templates. This is part of the effort to simplify the testing imports and hide compiler APIs. Closes #9585 BREAKING CHANGE: `TestComponentBuilder` is now imported from `@angular/core/testing`. Imports from `@angular/compiler/testing` are deprecated. Before: ``` import {TestComponentBuilder, TestComponentRenderer, ComponentFixtureAutoDetect} from '@angular/compiler/testing'; ``` After: ``` import {TestComponentBuilder, TestComponentRenderer, ComponentFixtureAutoDetect} from '@angular/core/testing'; ```
This commit is contained in:
parent
c693c03f1d
commit
a33195dcf3
|
@ -6,37 +6,44 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AnimationEntryMetadata, ChangeDetectorRef, ComponentFactory, ComponentRef, ComponentResolver, DebugElement, ElementRef, Injectable, Injector, NgZone, NgZoneError, OpaqueToken, ViewMetadata, getDebugNode} from '@angular/core';
|
import {AnimationEntryMetadata, ComponentFactory, ComponentResolver, Injectable, Injector, NgZone, ViewMetadata} from '@angular/core';
|
||||||
import {ComponentFixture, tick} from '@angular/core/testing';
|
import {ComponentFixture, ComponentFixtureNoNgZone, TestComponentBuilder} from '@angular/core/testing';
|
||||||
|
|
||||||
import {DirectiveResolver, ViewResolver} from '../index';
|
import {DirectiveResolver, ViewResolver} from '../index';
|
||||||
import {ObservableWrapper, PromiseCompleter, PromiseWrapper} from '../src/facade/async';
|
import {MapWrapper} from '../src/facade/collection';
|
||||||
import {ListWrapper, MapWrapper} from '../src/facade/collection';
|
import {IS_DART, Type, isPresent} from '../src/facade/lang';
|
||||||
import {BaseException} from '../src/facade/exceptions';
|
|
||||||
import {IS_DART, Type, isBlank, isPresent, scheduleMicroTask} from '../src/facade/lang';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated Import TestComponentRenderer from @angular/core/testing
|
||||||
* Import ComponentFixture from @angular/core/testing instead.
|
*/
|
||||||
|
export {TestComponentRenderer} from '@angular/core/testing';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Import TestComponentBuilder from @angular/core/testing
|
||||||
|
*/
|
||||||
|
export {TestComponentBuilder} from '@angular/core/testing';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Import ComponentFixture from @angular/core/testing
|
||||||
*/
|
*/
|
||||||
export {ComponentFixture} from '@angular/core/testing';
|
export {ComponentFixture} from '@angular/core/testing';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract class for inserting the root test component element in a platform independent way.
|
* @deprecated Import ComponentFixtureNoNgZone from @angular/core/testing
|
||||||
*/
|
*/
|
||||||
export class TestComponentRenderer {
|
export {ComponentFixtureNoNgZone} from '@angular/core/testing';
|
||||||
insertRootElement(rootElementId: string) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
export var ComponentFixtureAutoDetect = new OpaqueToken('ComponentFixtureAutoDetect');
|
|
||||||
export var ComponentFixtureNoNgZone = new OpaqueToken('ComponentFixtureNoNgZone');
|
|
||||||
|
|
||||||
var _nextRootElementId = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a ComponentFixture for use in component level tests.
|
* @deprecated Import ComponentFixtureAutoDetect from @angular/core/testing
|
||||||
|
*/
|
||||||
|
export {ComponentFixtureAutoDetect} from '@angular/core/testing';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A TestComponentBuilder that allows overriding based on the compiler.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TestComponentBuilder {
|
export class OverridingTestComponentBuilder extends TestComponentBuilder {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_bindingsOverrides = new Map<Type, any[]>();
|
_bindingsOverrides = new Map<Type, any[]>();
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
@ -51,11 +58,12 @@ export class TestComponentBuilder {
|
||||||
_viewOverrides = new Map<Type, ViewMetadata>();
|
_viewOverrides = new Map<Type, ViewMetadata>();
|
||||||
|
|
||||||
|
|
||||||
constructor(private _injector: Injector) {}
|
|
||||||
|
constructor(injector: Injector) { super(injector); }
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_clone(): TestComponentBuilder {
|
_clone(): OverridingTestComponentBuilder {
|
||||||
let clone = new TestComponentBuilder(this._injector);
|
let clone = new OverridingTestComponentBuilder(this._injector);
|
||||||
clone._viewOverrides = MapWrapper.clone(this._viewOverrides);
|
clone._viewOverrides = MapWrapper.clone(this._viewOverrides);
|
||||||
clone._directiveOverrides = MapWrapper.clone(this._directiveOverrides);
|
clone._directiveOverrides = MapWrapper.clone(this._directiveOverrides);
|
||||||
clone._templateOverrides = MapWrapper.clone(this._templateOverrides);
|
clone._templateOverrides = MapWrapper.clone(this._templateOverrides);
|
||||||
|
@ -64,11 +72,7 @@ export class TestComponentBuilder {
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
overrideTemplate(componentType: Type, template: string): OverridingTestComponentBuilder {
|
||||||
* Overrides only the html of a {@link ComponentMetadata}.
|
|
||||||
* All the other properties of the component's {@link ViewMetadata} are preserved.
|
|
||||||
*/
|
|
||||||
overrideTemplate(componentType: Type, template: string): TestComponentBuilder {
|
|
||||||
let clone = this._clone();
|
let clone = this._clone();
|
||||||
clone._templateOverrides.set(componentType, template);
|
clone._templateOverrides.set(componentType, template);
|
||||||
return clone;
|
return clone;
|
||||||
|
@ -81,19 +85,13 @@ export class TestComponentBuilder {
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
overrideView(componentType: Type, view: ViewMetadata): OverridingTestComponentBuilder {
|
||||||
* Overrides a component's {@link ViewMetadata}.
|
|
||||||
*/
|
|
||||||
overrideView(componentType: Type, view: ViewMetadata): TestComponentBuilder {
|
|
||||||
let clone = this._clone();
|
let clone = this._clone();
|
||||||
clone._viewOverrides.set(componentType, view);
|
clone._viewOverrides.set(componentType, view);
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
overrideDirective(componentType: Type, from: Type, to: Type): OverridingTestComponentBuilder {
|
||||||
* Overrides the directives from the component {@link ViewMetadata}.
|
|
||||||
*/
|
|
||||||
overrideDirective(componentType: Type, from: Type, to: Type): TestComponentBuilder {
|
|
||||||
let clone = this._clone();
|
let clone = this._clone();
|
||||||
let overridesForComponent = clone._directiveOverrides.get(componentType);
|
let overridesForComponent = clone._directiveOverrides.get(componentType);
|
||||||
if (!isPresent(overridesForComponent)) {
|
if (!isPresent(overridesForComponent)) {
|
||||||
|
@ -104,65 +102,18 @@ export class TestComponentBuilder {
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
overrideProviders(type: Type, providers: any[]): OverridingTestComponentBuilder {
|
||||||
* Overrides one or more injectables configured via `providers` metadata property of a directive
|
|
||||||
* or
|
|
||||||
* component.
|
|
||||||
* Very useful when certain providers need to be mocked out.
|
|
||||||
*
|
|
||||||
* The providers specified via this method are appended to the existing `providers` causing the
|
|
||||||
* duplicated providers to
|
|
||||||
* be overridden.
|
|
||||||
*/
|
|
||||||
overrideProviders(type: Type, providers: any[]): TestComponentBuilder {
|
|
||||||
let clone = this._clone();
|
let clone = this._clone();
|
||||||
clone._bindingsOverrides.set(type, providers);
|
clone._bindingsOverrides.set(type, providers);
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
overrideViewProviders(type: Type, providers: any[]): OverridingTestComponentBuilder {
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
overrideBindings(type: Type, providers: any[]): TestComponentBuilder {
|
|
||||||
return this.overrideProviders(type, providers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overrides one or more injectables configured via `providers` metadata property of a directive
|
|
||||||
* or
|
|
||||||
* component.
|
|
||||||
* Very useful when certain providers need to be mocked out.
|
|
||||||
*
|
|
||||||
* The providers specified via this method are appended to the existing `providers` causing the
|
|
||||||
* duplicated providers to
|
|
||||||
* be overridden.
|
|
||||||
*/
|
|
||||||
overrideViewProviders(type: Type, providers: any[]): TestComponentBuilder {
|
|
||||||
let clone = this._clone();
|
let clone = this._clone();
|
||||||
clone._viewBindingsOverrides.set(type, providers);
|
clone._viewBindingsOverrides.set(type, providers);
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
overrideViewBindings(type: Type, providers: any[]): TestComponentBuilder {
|
|
||||||
return this.overrideViewProviders(type, providers);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _create<C>(ngZone: NgZone, componentFactory: ComponentFactory<C>): ComponentFixture<C> {
|
|
||||||
let rootElId = `root${_nextRootElementId++}`;
|
|
||||||
var testComponentRenderer: TestComponentRenderer = this._injector.get(TestComponentRenderer);
|
|
||||||
testComponentRenderer.insertRootElement(rootElId);
|
|
||||||
|
|
||||||
var componentRef = componentFactory.create(this._injector, [], `#${rootElId}`);
|
|
||||||
let autoDetect: boolean = this._injector.get(ComponentFixtureAutoDetect, false);
|
|
||||||
return new ComponentFixture<any /*C*/>(componentRef, ngZone, autoDetect);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds and returns a ComponentFixture.
|
|
||||||
*/
|
|
||||||
createAsync(rootComponentType: Type): Promise<ComponentFixture<any>> {
|
createAsync(rootComponentType: Type): Promise<ComponentFixture<any>> {
|
||||||
let noNgZone = IS_DART || this._injector.get(ComponentFixtureNoNgZone, false);
|
let noNgZone = IS_DART || this._injector.get(ComponentFixtureNoNgZone, false);
|
||||||
let ngZone: NgZone = noNgZone ? null : this._injector.get(NgZone, null);
|
let ngZone: NgZone = noNgZone ? null : this._injector.get(NgZone, null);
|
||||||
|
@ -186,30 +137,9 @@ export class TestComponentBuilder {
|
||||||
|
|
||||||
let promise: Promise<ComponentFactory<any>> =
|
let promise: Promise<ComponentFactory<any>> =
|
||||||
this._injector.get(ComponentResolver).resolveComponent(rootComponentType);
|
this._injector.get(ComponentResolver).resolveComponent(rootComponentType);
|
||||||
return promise.then(componentFactory => this._create(ngZone, componentFactory));
|
return promise.then(componentFactory => this.createFromFactory(ngZone, componentFactory));
|
||||||
};
|
};
|
||||||
|
|
||||||
return ngZone == null ? initComponent() : ngZone.run(initComponent);
|
return ngZone == null ? initComponent() : ngZone.run(initComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
createFakeAsync(rootComponentType: Type): ComponentFixture<any> {
|
|
||||||
let result: any /** TODO #9100 */;
|
|
||||||
let error: any /** TODO #9100 */;
|
|
||||||
PromiseWrapper.then(
|
|
||||||
this.createAsync(rootComponentType), (_result) => { result = _result; },
|
|
||||||
(_error) => { error = _error; });
|
|
||||||
tick();
|
|
||||||
if (isPresent(error)) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
createSync<C>(componentFactory: ComponentFactory<C>): ComponentFixture<C> {
|
|
||||||
let noNgZone = IS_DART || this._injector.get(ComponentFixtureNoNgZone, false);
|
|
||||||
let ngZone: NgZone = noNgZone ? null : this._injector.get(NgZone, null);
|
|
||||||
|
|
||||||
let initComponent = () => this._create(ngZone, componentFactory);
|
|
||||||
return ngZone == null ? initComponent() : ngZone.run(initComponent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,6 @@
|
||||||
export * from './testing/async';
|
export * from './testing/async';
|
||||||
export * from './testing/component_fixture';
|
export * from './testing/component_fixture';
|
||||||
export * from './testing/fake_async';
|
export * from './testing/fake_async';
|
||||||
|
export * from './testing/test_component_builder';
|
||||||
export * from './testing/test_injector';
|
export * from './testing/test_injector';
|
||||||
export * from './testing/testing';
|
export * from './testing/testing';
|
||||||
|
|
|
@ -0,0 +1,148 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright Google Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
|
* found in the LICENSE file at https://angular.io/license
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {AnimationEntryMetadata, ComponentFactory, ComponentResolver, Injectable, Injector, NgZone, OpaqueToken, ViewMetadata} from '../index';
|
||||||
|
import {PromiseWrapper} from '../src/facade/async';
|
||||||
|
import {IS_DART, Type, isPresent} from '../src/facade/lang';
|
||||||
|
|
||||||
|
import {ComponentFixture} from './component_fixture';
|
||||||
|
import {tick} from './fake_async';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract class for inserting the root test component element in a platform independent way.
|
||||||
|
*/
|
||||||
|
export class TestComponentRenderer {
|
||||||
|
insertRootElement(rootElementId: string) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export var ComponentFixtureAutoDetect = new OpaqueToken('ComponentFixtureAutoDetect');
|
||||||
|
export var ComponentFixtureNoNgZone = new OpaqueToken('ComponentFixtureNoNgZone');
|
||||||
|
|
||||||
|
var _nextRootElementId = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a ComponentFixture for use in component level tests.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class TestComponentBuilder {
|
||||||
|
constructor(protected _injector: Injector) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides only the html of a {@link ComponentMetadata}.
|
||||||
|
* All the other properties of the component's {@link ViewMetadata} are preserved.
|
||||||
|
*/
|
||||||
|
overrideTemplate(componentType: Type, template: string): TestComponentBuilder {
|
||||||
|
throw new Error(
|
||||||
|
'overrideTemplate is not supported in this implementation of TestComponentBuilder.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides a component's {@link ViewMetadata}.
|
||||||
|
*/
|
||||||
|
overrideView(componentType: Type, view: ViewMetadata): TestComponentBuilder {
|
||||||
|
throw new Error(
|
||||||
|
'overrideView is not supported in this implementation of TestComponentBuilder.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides the directives from the component {@link ViewMetadata}.
|
||||||
|
*/
|
||||||
|
overrideDirective(componentType: Type, from: Type, to: Type): TestComponentBuilder {
|
||||||
|
throw new Error(
|
||||||
|
'overrideDirective is not supported in this implementation of TestComponentBuilder.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides one or more injectables configured via `providers` metadata property of a directive
|
||||||
|
* or
|
||||||
|
* component.
|
||||||
|
* Very useful when certain providers need to be mocked out.
|
||||||
|
*
|
||||||
|
* The providers specified via this method are appended to the existing `providers` causing the
|
||||||
|
* duplicated providers to
|
||||||
|
* be overridden.
|
||||||
|
*/
|
||||||
|
overrideProviders(type: Type, providers: any[]): TestComponentBuilder {
|
||||||
|
throw new Error(
|
||||||
|
'overrideProviders is not supported in this implementation of TestComponentBuilder.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides one or more injectables configured via `providers` metadata property of a directive
|
||||||
|
* or
|
||||||
|
* component.
|
||||||
|
* Very useful when certain providers need to be mocked out.
|
||||||
|
*
|
||||||
|
* The providers specified via this method are appended to the existing `providers` causing the
|
||||||
|
* duplicated providers to
|
||||||
|
* be overridden.
|
||||||
|
*/
|
||||||
|
overrideViewProviders(type: Type, providers: any[]): TestComponentBuilder {
|
||||||
|
throw new Error(
|
||||||
|
'overrideViewProviders is not supported in this implementation of TestComponentBuilder.');
|
||||||
|
}
|
||||||
|
|
||||||
|
overrideAnimations(componentType: Type, animations: AnimationEntryMetadata[]):
|
||||||
|
TestComponentBuilder {
|
||||||
|
throw new Error(
|
||||||
|
'overrideAnimations is not supported in this implementation of TestComponentBuilder.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected createFromFactory<C>(ngZone: NgZone, componentFactory: ComponentFactory<C>):
|
||||||
|
ComponentFixture<C> {
|
||||||
|
let rootElId = `root${_nextRootElementId++}`;
|
||||||
|
var testComponentRenderer: TestComponentRenderer = this._injector.get(TestComponentRenderer);
|
||||||
|
testComponentRenderer.insertRootElement(rootElId);
|
||||||
|
|
||||||
|
var componentRef = componentFactory.create(this._injector, [], `#${rootElId}`);
|
||||||
|
let autoDetect: boolean = this._injector.get(ComponentFixtureAutoDetect, false);
|
||||||
|
return new ComponentFixture<any /*C*/>(componentRef, ngZone, autoDetect);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds and returns a ComponentFixture.
|
||||||
|
*/
|
||||||
|
createAsync(rootComponentType: Type): Promise<ComponentFixture<any>> {
|
||||||
|
let noNgZone = IS_DART || this._injector.get(ComponentFixtureNoNgZone, false);
|
||||||
|
let ngZone: NgZone = noNgZone ? null : this._injector.get(NgZone, null);
|
||||||
|
|
||||||
|
let initComponent = () => {
|
||||||
|
let promise: Promise<ComponentFactory<any>> =
|
||||||
|
this._injector.get(ComponentResolver).resolveComponent(rootComponentType);
|
||||||
|
return promise.then(componentFactory => this.createFromFactory(ngZone, componentFactory));
|
||||||
|
};
|
||||||
|
|
||||||
|
return ngZone == null ? initComponent() : ngZone.run(initComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
createFakeAsync(rootComponentType: Type): ComponentFixture<any> {
|
||||||
|
let result: any /** TODO #9100 */;
|
||||||
|
let error: any /** TODO #9100 */;
|
||||||
|
PromiseWrapper.then(
|
||||||
|
this.createAsync(rootComponentType), (_result) => { result = _result; },
|
||||||
|
(_error) => { error = _error; });
|
||||||
|
tick();
|
||||||
|
if (isPresent(error)) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated createSync will be replaced with the ability to precompile components from within
|
||||||
|
* the test.
|
||||||
|
*/
|
||||||
|
createSync<C>(componentFactory: ComponentFactory<C>): ComponentFixture<C> {
|
||||||
|
let noNgZone = IS_DART || this._injector.get(ComponentFixtureNoNgZone, false);
|
||||||
|
let ngZone: NgZone = noNgZone ? null : this._injector.get(NgZone, null);
|
||||||
|
|
||||||
|
let initComponent = () => this.createFromFactory(ngZone, componentFactory);
|
||||||
|
return ngZone == null ? initComponent() : ngZone.run(initComponent);
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {DirectiveResolver, ViewResolver} from '@angular/compiler';
|
import {DirectiveResolver, ViewResolver} from '@angular/compiler';
|
||||||
import {MockDirectiveResolver, MockViewResolver, TestComponentBuilder, TestComponentRenderer} from '@angular/compiler/testing';
|
import {MockDirectiveResolver, MockViewResolver, OverridingTestComponentBuilder} from '@angular/compiler/testing';
|
||||||
|
import {TestComponentBuilder, TestComponentRenderer} from '@angular/core/testing';
|
||||||
import {TEST_BROWSER_APPLICATION_PROVIDERS, TEST_BROWSER_PLATFORM_PROVIDERS} from '@angular/platform-browser/testing';
|
import {TEST_BROWSER_APPLICATION_PROVIDERS, TEST_BROWSER_PLATFORM_PROVIDERS} from '@angular/platform-browser/testing';
|
||||||
|
|
||||||
import {BROWSER_APP_COMPILER_PROVIDERS} from './index';
|
import {BROWSER_APP_COMPILER_PROVIDERS} from './index';
|
||||||
|
@ -27,9 +28,9 @@ export const TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS: Array<any /*Type | Provide
|
||||||
export const TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
export const TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
||||||
TEST_BROWSER_APPLICATION_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS,
|
TEST_BROWSER_APPLICATION_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS,
|
||||||
[
|
[
|
||||||
|
{provide: TestComponentBuilder, useClass: OverridingTestComponentBuilder},
|
||||||
{provide: DirectiveResolver, useClass: MockDirectiveResolver},
|
{provide: DirectiveResolver, useClass: MockDirectiveResolver},
|
||||||
{provide: ViewResolver, useClass: MockViewResolver},
|
{provide: ViewResolver, useClass: MockViewResolver},
|
||||||
TestComponentBuilder,
|
|
||||||
{provide: TestComponentRenderer, useClass: DOMTestComponentRenderer},
|
{provide: TestComponentRenderer, useClass: DOMTestComponentRenderer},
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {COMPILER_PROVIDERS, DirectiveResolver, ViewResolver, XHR} from '@angular/compiler';
|
import {COMPILER_PROVIDERS, DirectiveResolver, ViewResolver, XHR} from '@angular/compiler';
|
||||||
import {MockDirectiveResolver, MockViewResolver, TestComponentBuilder, TestComponentRenderer} from '@angular/compiler/testing';
|
import {MockDirectiveResolver, MockViewResolver, OverridingTestComponentBuilder} from '@angular/compiler/testing';
|
||||||
import {APPLICATION_COMMON_PROVIDERS, APP_ID, NgZone, PLATFORM_COMMON_PROVIDERS, PLATFORM_INITIALIZER, RootRenderer} from '@angular/core';
|
import {APPLICATION_COMMON_PROVIDERS, APP_ID, NgZone, PLATFORM_COMMON_PROVIDERS, PLATFORM_INITIALIZER, RootRenderer} from '@angular/core';
|
||||||
|
import {TestComponentBuilder, TestComponentRenderer} from '@angular/core/testing';
|
||||||
|
|
||||||
import {AnimationDriver, NoOpAnimationDriver} from '../core_private';
|
import {AnimationDriver, NoOpAnimationDriver} from '../core_private';
|
||||||
import {DOMTestComponentRenderer} from '../platform_browser_dynamic_testing_private';
|
import {DOMTestComponentRenderer} from '../platform_browser_dynamic_testing_private';
|
||||||
|
@ -71,9 +72,9 @@ export const TEST_SERVER_APPLICATION_PROVIDERS: Array<any /*Type | Provider | an
|
||||||
/* @ts2dart_Provider */ {provide: APP_ID, useValue: 'a'},
|
/* @ts2dart_Provider */ {provide: APP_ID, useValue: 'a'},
|
||||||
/* @ts2dart_Provider */ {provide: SharedStylesHost, useExisting: DomSharedStylesHost},
|
/* @ts2dart_Provider */ {provide: SharedStylesHost, useExisting: DomSharedStylesHost},
|
||||||
DomSharedStylesHost, ELEMENT_PROBE_PROVIDERS,
|
DomSharedStylesHost, ELEMENT_PROBE_PROVIDERS,
|
||||||
|
{provide: TestComponentBuilder, useClass: OverridingTestComponentBuilder},
|
||||||
/* @ts2dart_Provider */ {provide: DirectiveResolver, useClass: MockDirectiveResolver},
|
/* @ts2dart_Provider */ {provide: DirectiveResolver, useClass: MockDirectiveResolver},
|
||||||
/* @ts2dart_Provider */ {provide: ViewResolver, useClass: MockViewResolver},
|
/* @ts2dart_Provider */ {provide: ViewResolver, useClass: MockViewResolver},
|
||||||
/* @ts2dart_Provider */ {provide: TestComponentRenderer, useClass: DOMTestComponentRenderer},
|
/* @ts2dart_Provider */ {provide: TestComponentRenderer, useClass: DOMTestComponentRenderer},
|
||||||
TestComponentBuilder,
|
|
||||||
/* @ts2dart_Provider */ {provide: NgZone, useFactory: createNgZone}
|
/* @ts2dart_Provider */ {provide: NgZone, useFactory: createNgZone}
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
export declare var ComponentFixtureAutoDetect: OpaqueToken;
|
|
||||||
|
|
||||||
export declare var ComponentFixtureNoNgZone: OpaqueToken;
|
|
||||||
|
|
||||||
export declare class MockDirectiveResolver extends DirectiveResolver {
|
export declare class MockDirectiveResolver extends DirectiveResolver {
|
||||||
resolve(type: Type): DirectiveMetadata;
|
resolve(type: Type): DirectiveMetadata;
|
||||||
setProvidersOverride(type: Type, providers: any[]): void;
|
setProvidersOverride(type: Type, providers: any[]): void;
|
||||||
|
@ -34,21 +30,13 @@ export declare class MockViewResolver extends ViewResolver {
|
||||||
setView(component: Type, view: ViewMetadata): void;
|
setView(component: Type, view: ViewMetadata): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class TestComponentBuilder {
|
export declare class OverridingTestComponentBuilder extends TestComponentBuilder {
|
||||||
constructor(_injector: Injector);
|
constructor(injector: Injector);
|
||||||
createAsync(rootComponentType: Type): Promise<ComponentFixture<any>>;
|
createAsync(rootComponentType: Type): Promise<ComponentFixture<any>>;
|
||||||
createFakeAsync(rootComponentType: Type): ComponentFixture<any>;
|
|
||||||
createSync<C>(componentFactory: ComponentFactory<C>): ComponentFixture<C>;
|
|
||||||
overrideAnimations(componentType: Type, animations: AnimationEntryMetadata[]): TestComponentBuilder;
|
overrideAnimations(componentType: Type, animations: AnimationEntryMetadata[]): TestComponentBuilder;
|
||||||
overrideBindings(type: Type, providers: any[]): TestComponentBuilder;
|
overrideDirective(componentType: Type, from: Type, to: Type): OverridingTestComponentBuilder;
|
||||||
overrideDirective(componentType: Type, from: Type, to: Type): TestComponentBuilder;
|
overrideProviders(type: Type, providers: any[]): OverridingTestComponentBuilder;
|
||||||
overrideProviders(type: Type, providers: any[]): TestComponentBuilder;
|
overrideTemplate(componentType: Type, template: string): OverridingTestComponentBuilder;
|
||||||
overrideTemplate(componentType: Type, template: string): TestComponentBuilder;
|
overrideView(componentType: Type, view: ViewMetadata): OverridingTestComponentBuilder;
|
||||||
overrideView(componentType: Type, view: ViewMetadata): TestComponentBuilder;
|
overrideViewProviders(type: Type, providers: any[]): OverridingTestComponentBuilder;
|
||||||
overrideViewBindings(type: Type, providers: any[]): TestComponentBuilder;
|
|
||||||
overrideViewProviders(type: Type, providers: any[]): TestComponentBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
export declare class TestComponentRenderer {
|
|
||||||
insertRootElement(rootElementId: string): void;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,10 @@ export declare class ComponentFixture<T> {
|
||||||
whenStable(): Promise<any>;
|
whenStable(): Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export declare var ComponentFixtureAutoDetect: OpaqueToken;
|
||||||
|
|
||||||
|
export declare var ComponentFixtureNoNgZone: OpaqueToken;
|
||||||
|
|
||||||
export declare var ddescribe: Function;
|
export declare var ddescribe: Function;
|
||||||
|
|
||||||
export declare var describe: Function;
|
export declare var describe: Function;
|
||||||
|
@ -56,6 +60,25 @@ export declare function resetBaseTestProviders(): void;
|
||||||
|
|
||||||
export declare function setBaseTestProviders(platformProviders: Array<Type | Provider | any[]>, applicationProviders: Array<Type | Provider | any[]>): void;
|
export declare function setBaseTestProviders(platformProviders: Array<Type | Provider | any[]>, applicationProviders: Array<Type | Provider | any[]>): void;
|
||||||
|
|
||||||
|
export declare class TestComponentBuilder {
|
||||||
|
protected _injector: Injector;
|
||||||
|
constructor(_injector: Injector);
|
||||||
|
createAsync(rootComponentType: Type): Promise<ComponentFixture<any>>;
|
||||||
|
createFakeAsync(rootComponentType: Type): ComponentFixture<any>;
|
||||||
|
protected createFromFactory<C>(ngZone: NgZone, componentFactory: ComponentFactory<C>): ComponentFixture<C>;
|
||||||
|
createSync<C>(componentFactory: ComponentFactory<C>): ComponentFixture<C>;
|
||||||
|
overrideAnimations(componentType: Type, animations: AnimationEntryMetadata[]): TestComponentBuilder;
|
||||||
|
overrideDirective(componentType: Type, from: Type, to: Type): TestComponentBuilder;
|
||||||
|
overrideProviders(type: Type, providers: any[]): TestComponentBuilder;
|
||||||
|
overrideTemplate(componentType: Type, template: string): TestComponentBuilder;
|
||||||
|
overrideView(componentType: Type, view: ViewMetadata): TestComponentBuilder;
|
||||||
|
overrideViewProviders(type: Type, providers: any[]): TestComponentBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare class TestComponentRenderer {
|
||||||
|
insertRootElement(rootElementId: string): void;
|
||||||
|
}
|
||||||
|
|
||||||
export declare class TestInjector {
|
export declare class TestInjector {
|
||||||
applicationProviders: Array<Type | Provider | any[] | any>;
|
applicationProviders: Array<Type | Provider | any[] | any>;
|
||||||
platformProviders: Array<Type | Provider | any[] | any>;
|
platformProviders: Array<Type | Provider | any[] | any>;
|
||||||
|
|
Loading…
Reference in New Issue