refactor(test_injector): Provide separate methods for creating test injector with and without runtime compiler.
BREAKING CHANGE: `createTestInjector()` does not more include the runtime compiler. Use `createTestInjectorWithRuntimeCompiler()` instead. Closes #5583
This commit is contained in:
parent
0a3a17ff10
commit
0614797d84
|
@ -57,6 +57,7 @@ import {COMPILER_PROVIDERS} from 'angular2/src/compiler/compiler';
|
|||
import {DomRenderer_} from "angular2/src/platform/dom/dom_renderer";
|
||||
import {DynamicComponentLoader_} from "angular2/src/core/linker/dynamic_component_loader";
|
||||
import {AppViewManager_} from "angular2/src/core/linker/view_manager";
|
||||
import {APPLICATION_COMMON_PROVIDERS} from 'angular2/src/core/application_common_providers';
|
||||
|
||||
/**
|
||||
* Returns the root injector providers.
|
||||
|
@ -87,7 +88,7 @@ function _getAppBindings() {
|
|||
}
|
||||
|
||||
return [
|
||||
COMPILER_PROVIDERS,
|
||||
APPLICATION_COMMON_PROVIDERS,
|
||||
provide(ChangeDetectorGenConfig, {useValue: new ChangeDetectorGenConfig(true, false, true)}),
|
||||
provide(DOCUMENT, {useValue: appDoc}),
|
||||
provide(DomRenderer, {useClass: DomRenderer_}),
|
||||
|
@ -120,11 +121,23 @@ function _getAppBindings() {
|
|||
];
|
||||
}
|
||||
|
||||
function _runtimeCompilerBindings() {
|
||||
return [
|
||||
provide(XHR, {useClass: DOM.getXHR()}),
|
||||
COMPILER_PROVIDERS,
|
||||
];
|
||||
}
|
||||
|
||||
export function createTestInjector(providers: Array<Type | Provider | any[]>): Injector {
|
||||
var rootInjector = Injector.resolveAndCreate(_getRootProviders());
|
||||
return rootInjector.resolveAndCreateChild(ListWrapper.concat(_getAppBindings(), providers));
|
||||
}
|
||||
|
||||
export function createTestInjectorWithRuntimeCompiler(
|
||||
providers: Array<Type | Provider | any[]>): Injector {
|
||||
return createTestInjector(ListWrapper.concat(_runtimeCompilerBindings(), providers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows injecting dependencies in `beforeEach()` and `it()`. When using with the
|
||||
* `angular2/testing` library, the test function will be run within a zone and will
|
||||
|
|
|
@ -6,7 +6,12 @@ import {global} from 'angular2/src/facade/lang';
|
|||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {bind} from 'angular2/src/core/di';
|
||||
|
||||
import {createTestInjector, FunctionWithParamTokens, inject, injectAsync} from './test_injector';
|
||||
import {
|
||||
createTestInjectorWithRuntimeCompiler,
|
||||
FunctionWithParamTokens,
|
||||
inject,
|
||||
injectAsync
|
||||
} from './test_injector';
|
||||
|
||||
export {inject, injectAsync} from './test_injector';
|
||||
|
||||
|
@ -150,7 +155,7 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An
|
|||
if (testFn instanceof FunctionWithParamTokens) {
|
||||
jsmFn(name, (done) => {
|
||||
if (!injector) {
|
||||
injector = createTestInjector(testProviders);
|
||||
injector = createTestInjectorWithRuntimeCompiler(testProviders);
|
||||
}
|
||||
|
||||
var returnedTestValue = runInTestZone(() => testFn.execute(injector), done, done.fail);
|
||||
|
@ -179,7 +184,7 @@ export function beforeEach(fn: FunctionWithParamTokens | AnyTestFn): void {
|
|||
|
||||
jsmBeforeEach((done) => {
|
||||
if (!injector) {
|
||||
injector = createTestInjector(testProviders);
|
||||
injector = createTestInjectorWithRuntimeCompiler(testProviders);
|
||||
}
|
||||
|
||||
runInTestZone(() => fn.execute(injector), done, done.fail);
|
||||
|
|
|
@ -63,7 +63,7 @@ void testSetup() {
|
|||
gns.beforeEach(() {
|
||||
_isCurrentTestAsync = false;
|
||||
_testBindings.add(completerBinding);
|
||||
_injector = createTestInjector(_testBindings);
|
||||
_injector = createTestInjectorWithRuntimeCompiler(_testBindings);
|
||||
}, priority: 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,11 @@ import {NgZoneZone} from 'angular2/src/core/zone/ng_zone';
|
|||
|
||||
import {provide} from 'angular2/src/core/di';
|
||||
|
||||
import {createTestInjector, FunctionWithParamTokens, inject} from './test_injector';
|
||||
import {
|
||||
createTestInjectorWithRuntimeCompiler,
|
||||
FunctionWithParamTokens,
|
||||
inject
|
||||
} from './test_injector';
|
||||
import {browserDetection} from './utils';
|
||||
|
||||
export {inject} from './test_injector';
|
||||
|
@ -143,7 +147,7 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An
|
|||
}
|
||||
});
|
||||
|
||||
var injector = createTestInjector([...testProviders, completerProvider]);
|
||||
var injector = createTestInjectorWithRuntimeCompiler([...testProviders, completerProvider]);
|
||||
runner.run(injector);
|
||||
|
||||
inIt = true;
|
||||
|
@ -152,7 +156,7 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An
|
|||
}, timeOut);
|
||||
} else {
|
||||
jsmFn(name, () => {
|
||||
var injector = createTestInjector(testProviders);
|
||||
var injector = createTestInjectorWithRuntimeCompiler(testProviders);
|
||||
runner.run(injector);
|
||||
testFn.execute(injector);
|
||||
}, timeOut);
|
||||
|
@ -163,13 +167,13 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An
|
|||
|
||||
if ((<any>testFn).length === 0) {
|
||||
jsmFn(name, () => {
|
||||
var injector = createTestInjector(testProviders);
|
||||
var injector = createTestInjectorWithRuntimeCompiler(testProviders);
|
||||
runner.run(injector);
|
||||
(<SyncTestFn>testFn)();
|
||||
}, timeOut);
|
||||
} else {
|
||||
jsmFn(name, (done) => {
|
||||
var injector = createTestInjector(testProviders);
|
||||
var injector = createTestInjectorWithRuntimeCompiler(testProviders);
|
||||
runner.run(injector);
|
||||
(<AsyncTestFn>testFn)(done);
|
||||
}, timeOut);
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
it,
|
||||
expect,
|
||||
beforeEach,
|
||||
createTestInjector,
|
||||
createTestInjectorWithRuntimeCompiler,
|
||||
beforeEachProviders,
|
||||
SpyObject,
|
||||
proxy
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
it,
|
||||
expect,
|
||||
beforeEach,
|
||||
createTestInjector,
|
||||
createTestInjectorWithRuntimeCompiler,
|
||||
beforeEachProviders,
|
||||
SpyObject,
|
||||
proxy
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
it,
|
||||
expect,
|
||||
beforeEach,
|
||||
createTestInjector,
|
||||
createTestInjectorWithRuntimeCompiler,
|
||||
beforeEachProviders,
|
||||
SpyObject,
|
||||
proxy
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
iit,
|
||||
expect,
|
||||
beforeEach,
|
||||
createTestInjector,
|
||||
createTestInjectorWithRuntimeCompiler,
|
||||
beforeEachProviders,
|
||||
TestComponentBuilder
|
||||
} from "angular2/testing_internal";
|
||||
|
@ -101,7 +101,7 @@ export function main() {
|
|||
beforeEachProviders(() => {
|
||||
var uiRenderProtoViewStore = new RenderProtoViewRefStore(false);
|
||||
uiRenderViewStore = new RenderViewWithFragmentsStore(false);
|
||||
uiInjector = createTestInjector([
|
||||
uiInjector = createTestInjectorWithRuntimeCompiler([
|
||||
provide(RenderProtoViewRefStore, {useValue: uiRenderProtoViewStore}),
|
||||
provide(RenderViewWithFragmentsStore, {useValue: uiRenderViewStore}),
|
||||
provide(DomRenderer, {useClass: DomRenderer_}),
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
it,
|
||||
expect,
|
||||
beforeEach,
|
||||
createTestInjector,
|
||||
createTestInjectorWithRuntimeCompiler,
|
||||
beforeEachProviders
|
||||
} from 'angular2/testing_internal';
|
||||
import {SpyMessageBroker} from './spies';
|
||||
|
|
|
@ -73,7 +73,7 @@ dynamic _runInjectableFunction(Function fn) {
|
|||
}
|
||||
|
||||
if (_currentInjector == null) {
|
||||
_currentInjector = createTestInjector(_currentTestProviders);
|
||||
_currentInjector = createTestInjectorWithRuntimeCompiler(_currentTestProviders);
|
||||
}
|
||||
var injectFn = new FunctionWithParamTokens(tokens, fn, false);
|
||||
return injectFn.execute(_currentInjector);
|
||||
|
|
Loading…
Reference in New Issue