X Tutup
Skip to content

Commit 0614797

Browse files
committed
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 angular#5583
1 parent 0a3a17f commit 0614797

File tree

10 files changed

+39
-17
lines changed

10 files changed

+39
-17
lines changed

modules/angular2/src/testing/test_injector.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {COMPILER_PROVIDERS} from 'angular2/src/compiler/compiler';
5757
import {DomRenderer_} from "angular2/src/platform/dom/dom_renderer";
5858
import {DynamicComponentLoader_} from "angular2/src/core/linker/dynamic_component_loader";
5959
import {AppViewManager_} from "angular2/src/core/linker/view_manager";
60+
import {APPLICATION_COMMON_PROVIDERS} from 'angular2/src/core/application_common_providers';
6061

6162
/**
6263
* Returns the root injector providers.
@@ -87,7 +88,7 @@ function _getAppBindings() {
8788
}
8889

8990
return [
90-
COMPILER_PROVIDERS,
91+
APPLICATION_COMMON_PROVIDERS,
9192
provide(ChangeDetectorGenConfig, {useValue: new ChangeDetectorGenConfig(true, false, true)}),
9293
provide(DOCUMENT, {useValue: appDoc}),
9394
provide(DomRenderer, {useClass: DomRenderer_}),
@@ -120,11 +121,23 @@ function _getAppBindings() {
120121
];
121122
}
122123

124+
function _runtimeCompilerBindings() {
125+
return [
126+
provide(XHR, {useClass: DOM.getXHR()}),
127+
COMPILER_PROVIDERS,
128+
];
129+
}
130+
123131
export function createTestInjector(providers: Array<Type | Provider | any[]>): Injector {
124132
var rootInjector = Injector.resolveAndCreate(_getRootProviders());
125133
return rootInjector.resolveAndCreateChild(ListWrapper.concat(_getAppBindings(), providers));
126134
}
127135

136+
export function createTestInjectorWithRuntimeCompiler(
137+
providers: Array<Type | Provider | any[]>): Injector {
138+
return createTestInjector(ListWrapper.concat(_runtimeCompilerBindings(), providers));
139+
}
140+
128141
/**
129142
* Allows injecting dependencies in `beforeEach()` and `it()`. When using with the
130143
* `angular2/testing` library, the test function will be run within a zone and will

modules/angular2/src/testing/testing.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import {global} from 'angular2/src/facade/lang';
66
import {ListWrapper} from 'angular2/src/facade/collection';
77
import {bind} from 'angular2/src/core/di';
88

9-
import {createTestInjector, FunctionWithParamTokens, inject, injectAsync} from './test_injector';
9+
import {
10+
createTestInjectorWithRuntimeCompiler,
11+
FunctionWithParamTokens,
12+
inject,
13+
injectAsync
14+
} from './test_injector';
1015

1116
export {inject, injectAsync} from './test_injector';
1217

@@ -150,7 +155,7 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An
150155
if (testFn instanceof FunctionWithParamTokens) {
151156
jsmFn(name, (done) => {
152157
if (!injector) {
153-
injector = createTestInjector(testProviders);
158+
injector = createTestInjectorWithRuntimeCompiler(testProviders);
154159
}
155160

156161
var returnedTestValue = runInTestZone(() => testFn.execute(injector), done, done.fail);
@@ -179,7 +184,7 @@ export function beforeEach(fn: FunctionWithParamTokens | AnyTestFn): void {
179184

180185
jsmBeforeEach((done) => {
181186
if (!injector) {
182-
injector = createTestInjector(testProviders);
187+
injector = createTestInjectorWithRuntimeCompiler(testProviders);
183188
}
184189

185190
runInTestZone(() => fn.execute(injector), done, done.fail);

modules/angular2/src/testing/testing_internal.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void testSetup() {
6363
gns.beforeEach(() {
6464
_isCurrentTestAsync = false;
6565
_testBindings.add(completerBinding);
66-
_injector = createTestInjector(_testBindings);
66+
_injector = createTestInjectorWithRuntimeCompiler(_testBindings);
6767
}, priority: 1);
6868
}
6969

modules/angular2/src/testing/testing_internal.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {NgZoneZone} from 'angular2/src/core/zone/ng_zone';
55

66
import {provide} from 'angular2/src/core/di';
77

8-
import {createTestInjector, FunctionWithParamTokens, inject} from './test_injector';
8+
import {
9+
createTestInjectorWithRuntimeCompiler,
10+
FunctionWithParamTokens,
11+
inject
12+
} from './test_injector';
913
import {browserDetection} from './utils';
1014

1115
export {inject} from './test_injector';
@@ -143,7 +147,7 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An
143147
}
144148
});
145149

146-
var injector = createTestInjector([...testProviders, completerProvider]);
150+
var injector = createTestInjectorWithRuntimeCompiler([...testProviders, completerProvider]);
147151
runner.run(injector);
148152

149153
inIt = true;
@@ -152,7 +156,7 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An
152156
}, timeOut);
153157
} else {
154158
jsmFn(name, () => {
155-
var injector = createTestInjector(testProviders);
159+
var injector = createTestInjectorWithRuntimeCompiler(testProviders);
156160
runner.run(injector);
157161
testFn.execute(injector);
158162
}, timeOut);
@@ -163,13 +167,13 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An
163167

164168
if ((<any>testFn).length === 0) {
165169
jsmFn(name, () => {
166-
var injector = createTestInjector(testProviders);
170+
var injector = createTestInjectorWithRuntimeCompiler(testProviders);
167171
runner.run(injector);
168172
(<SyncTestFn>testFn)();
169173
}, timeOut);
170174
} else {
171175
jsmFn(name, (done) => {
172-
var injector = createTestInjector(testProviders);
176+
var injector = createTestInjectorWithRuntimeCompiler(testProviders);
173177
runner.run(injector);
174178
(<AsyncTestFn>testFn)(done);
175179
}, timeOut);

modules/angular2/test/web_workers/shared/message_bus_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
it,
66
expect,
77
beforeEach,
8-
createTestInjector,
8+
createTestInjectorWithRuntimeCompiler,
99
beforeEachProviders,
1010
SpyObject,
1111
proxy

modules/angular2/test/web_workers/shared/service_message_broker_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
it,
66
expect,
77
beforeEach,
8-
createTestInjector,
8+
createTestInjectorWithRuntimeCompiler,
99
beforeEachProviders,
1010
SpyObject,
1111
proxy

modules/angular2/test/web_workers/worker/event_dispatcher_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
it,
66
expect,
77
beforeEach,
8-
createTestInjector,
8+
createTestInjectorWithRuntimeCompiler,
99
beforeEachProviders,
1010
SpyObject,
1111
proxy

modules/angular2/test/web_workers/worker/renderer_integration_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
iit,
88
expect,
99
beforeEach,
10-
createTestInjector,
10+
createTestInjectorWithRuntimeCompiler,
1111
beforeEachProviders,
1212
TestComponentBuilder
1313
} from "angular2/testing_internal";
@@ -101,7 +101,7 @@ export function main() {
101101
beforeEachProviders(() => {
102102
var uiRenderProtoViewStore = new RenderProtoViewRefStore(false);
103103
uiRenderViewStore = new RenderViewWithFragmentsStore(false);
104-
uiInjector = createTestInjector([
104+
uiInjector = createTestInjectorWithRuntimeCompiler([
105105
provide(RenderProtoViewRefStore, {useValue: uiRenderProtoViewStore}),
106106
provide(RenderViewWithFragmentsStore, {useValue: uiRenderViewStore}),
107107
provide(DomRenderer, {useClass: DomRenderer_}),

modules/angular2/test/web_workers/worker/xhr_impl_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
it,
66
expect,
77
beforeEach,
8-
createTestInjector,
8+
createTestInjectorWithRuntimeCompiler,
99
beforeEachProviders
1010
} from 'angular2/testing_internal';
1111
import {SpyMessageBroker} from './spies';

modules_dart/angular2_testing/lib/angular2_testing.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ dynamic _runInjectableFunction(Function fn) {
7373
}
7474

7575
if (_currentInjector == null) {
76-
_currentInjector = createTestInjector(_currentTestProviders);
76+
_currentInjector = createTestInjectorWithRuntimeCompiler(_currentTestProviders);
7777
}
7878
var injectFn = new FunctionWithParamTokens(tokens, fn, false);
7979
return injectFn.execute(_currentInjector);

0 commit comments

Comments
 (0)
X Tutup