
This contains major changes to the compiler, bootstrap of the platforms and test environment initialization. Main part of #10043 Closes #10164 BREAKING CHANGE: - Semantics and name of `@AppModule` (now `@NgModule`) changed quite a bit. This is actually not breaking as `@AppModules` were not part of rc.4. We will have detailed docs on `@NgModule` separately. - `coreLoadAndBootstrap` and `coreBootstrap` can't be used any more (without migration support). Use `bootstrapModule` / `bootstrapModuleFactory` instead. - All Components listed in routes have to be part of the `declarations` of an NgModule. Either directly on the bootstrap module / lazy loaded module, or in an NgModule imported by them.
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
/**
|
|
* @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
|
|
*/
|
|
|
|
/**
|
|
* Public Test Library for unit testing Angular2 Applications. Assumes that you are running
|
|
* with Jasmine, Mocha, or a similar framework which exports a beforeEach function and
|
|
* allows tests to be asynchronous by either returning a promise or using a 'done' parameter.
|
|
*/
|
|
|
|
import {TestBed, getTestBed} from './test_bed';
|
|
|
|
declare var global: any;
|
|
|
|
var _global = <any>(typeof window === 'undefined' ? global : window);
|
|
|
|
var testBed: TestBed = getTestBed();
|
|
|
|
// Reset the test providers before each test.
|
|
if (_global.beforeEach) {
|
|
_global.beforeEach(() => { testBed.reset(); });
|
|
}
|
|
|
|
/**
|
|
* Allows overriding default providers of the test injector,
|
|
* which are defined in test_injector.js
|
|
*
|
|
* @stable
|
|
*/
|
|
export function addProviders(providers: Array<any>): void {
|
|
if (!providers) return;
|
|
try {
|
|
testBed.configureModule({providers: providers});
|
|
} catch (e) {
|
|
throw new Error(
|
|
'addProviders can\'t be called after the injector has been already created for this test. ' +
|
|
'This is most likely because you\'ve already used the injector to inject a beforeEach or the ' +
|
|
'current `it` function.');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Allows overriding default providers, directives, pipes, modules of the test injector,
|
|
* which are defined in test_injector.js
|
|
*
|
|
* @stable
|
|
*/
|
|
export function configureModule(
|
|
moduleDef: {providers?: any[], declarations?: any[], imports?: any[], precompile?: any[]}):
|
|
void {
|
|
if (!moduleDef) return;
|
|
try {
|
|
testBed.configureModule(moduleDef);
|
|
} catch (e) {
|
|
throw new Error(
|
|
'configureModule can\'t be called after the injector has been already created for this test. ' +
|
|
'This is most likely because you\'ve already used the injector to inject a beforeEach or the ' +
|
|
'current `it` function.');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Allows overriding default compiler providers and settings
|
|
* which are defined in test_injector.js
|
|
*
|
|
* @stable
|
|
*/
|
|
export function configureCompiler(config: {providers?: any[], useJit?: boolean}): void {
|
|
if (!config) return;
|
|
try {
|
|
testBed.configureCompiler(config);
|
|
} catch (e) {
|
|
throw new Error(
|
|
'configureCompiler can\'t be called after the injector has been already created for this test. ' +
|
|
'This is most likely because you\'ve already used the injector to inject a beforeEach or the ' +
|
|
'current `it` function.');
|
|
}
|
|
}
|