refactor(core/testing): remove deprecated TestComponentBuilder

BREAKING CHANGE: deprecated TestComponentBuilder was removed, please use TestBed instead
This commit is contained in:
Igor Minar
2016-08-19 13:49:36 -07:00
parent 3c2b2ff332
commit a29f9f3ab8
6 changed files with 3 additions and 281 deletions

View File

@ -1,144 +0,0 @@
/**
* @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, Compiler, ComponentFactory, Injectable, Injector, NgZone, OpaqueToken} from '../index';
import {isPresent} from '../src/facade/lang';
import {ViewMetadata} from '../src/metadata/view';
import {Type} from '../src/type';
import {ComponentFixture} from './component_fixture';
import {tick} from './fake_async';
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestComponentRenderer} from './test_bed';
var _nextRootElementId = 0;
/**
* Builds a ComponentFixture for use in component level tests.
*
* @deprecated Use `TestBed.configureTestModule` / `TestBed.override...` / `TestBed.createComponent`
* instead.
*/
@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<any>, template: string): TestComponentBuilder {
throw new Error(
'overrideTemplate is not supported in this implementation of TestComponentBuilder.');
}
/**
* Overrides a component's {@link ViewMetadata}.
*/
overrideView(componentType: Type<any>, 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<any>, from: Type<any>, to: Type<any>):
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<any>, 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<any>, providers: any[]): TestComponentBuilder {
throw new Error(
'overrideViewProviders is not supported in this implementation of TestComponentBuilder.');
}
overrideAnimations(componentType: Type<any>, 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<T>(rootComponentType: Type<T>): Promise<ComponentFixture<T>> {
let noNgZone = this._injector.get(ComponentFixtureNoNgZone, false);
let ngZone: NgZone = noNgZone ? null : this._injector.get(NgZone, null);
let compiler: Compiler = this._injector.get(Compiler);
let initComponent = () => {
let promise: Promise<ComponentFactory<any>> =
compiler.compileComponentAsync(rootComponentType);
return promise.then(componentFactory => this.createFromFactory(ngZone, componentFactory));
};
return ngZone == null ? initComponent() : ngZone.run(initComponent);
}
createFakeAsync<T>(rootComponentType: Type<T>): ComponentFixture<T> {
let result: any /** TODO #9100 */;
let error: any /** TODO #9100 */;
this.createAsync(rootComponentType)
.then((_result) => { result = _result; }, (_error) => { error = _error; });
tick();
if (isPresent(error)) {
throw error;
}
return result;
}
createSync<T>(rootComponentType: Type<T>): ComponentFixture<T> {
let noNgZone = this._injector.get(ComponentFixtureNoNgZone, false);
let ngZone: NgZone = noNgZone ? null : this._injector.get(NgZone, null);
let compiler: Compiler = this._injector.get(Compiler);
let initComponent = () => {
return this.createFromFactory(ngZone, compiler.compileComponentSync(rootComponentType));
};
return ngZone == null ? initComponent() : ngZone.run(initComponent);
}
}

View File

@ -7,7 +7,7 @@
*/
import {StringMapWrapper} from '../src/facade/collection';
import {Math, global, isFunction, isPromise} from '../src/facade/lang';
import {Math, global, isPromise} from '../src/facade/lang';
import {AsyncTestCompleter} from './async_test_completer';
import {TestBed, getTestBed, inject} from './test_bed';
@ -17,7 +17,6 @@ export {MockAnimationPlayer} from './mock_animation_player';
export {inject} from './test_bed';
export * from './logger';
export * from './ng_zone_mock';
export * from './test_component_builder';
export var proxy: ClassDecorator = (t: any /** TODO #9100 */) => t;