fix(core/testing): clean up the core testing public API (#9466)
Previously, we were exporting internal mocks and helpers. Move these to core/testing/testing_internal or remove them if they were never used. Remove deprecated items - injectAsync, clearPendingTimers. BREAKING CHANGE: Remove the following APIs from `@angular/core/testing`, which have been deprecated or were never intended to be publicly exported: ``` injectAsync clearPendingTimers Log MockAppliacationHref MockNgZone clearPendingTimers getTypeOf instantiateType ``` Instead of `injectAsync`, use `async(inject())`. `clearPendingTimers` is no longer required.
This commit is contained in:
@ -24,6 +24,11 @@
|
||||
export function async(fn: Function): Function {
|
||||
return () => new Promise<void>((finishCallback, failCallback) => {
|
||||
var AsyncTestZoneSpec = (Zone as any /** TODO #9100 */)['AsyncTestZoneSpec'];
|
||||
if (AsyncTestZoneSpec === undefined) {
|
||||
throw new Error(
|
||||
'AsyncTestZoneSpec is needed for the async() test helper but could not be found. ' +
|
||||
'Please make sure that your environment includes zone.js/dist/async-test.js');
|
||||
}
|
||||
var testZoneSpec = new AsyncTestZoneSpec(finishCallback, failCallback, 'test');
|
||||
var testZone = Zone.current.fork(testZoneSpec);
|
||||
return testZone.run(fn);
|
||||
|
@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import {BaseException} from '../index';
|
||||
import {getTestInjector} from './test_injector';
|
||||
|
||||
let _FakeAsyncTestZoneSpecType = (Zone as any /** TODO #9100 */)['FakeAsyncTestZoneSpec'];
|
||||
|
||||
@ -64,16 +63,6 @@ function _getFakeAsyncZoneSpec(): any {
|
||||
return zoneSpec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the queue of pending timers and microtasks.
|
||||
* Tests no longer need to call this explicitly.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function clearPendingTimers(): void {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates the asynchronous passage of time for the timers in the fakeAsync zone.
|
||||
*
|
||||
|
@ -11,12 +11,8 @@ import {lockRunMode} from '../src/application_ref';
|
||||
import {ListWrapper} from '../src/facade/collection';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {FunctionWrapper, isPresent} from '../src/facade/lang';
|
||||
|
||||
import {async} from './async';
|
||||
import {AsyncTestCompleter} from './async_test_completer';
|
||||
|
||||
export {async} from './async';
|
||||
|
||||
export class TestInjector {
|
||||
private _instantiated: boolean = false;
|
||||
|
||||
@ -168,42 +164,12 @@ export class InjectSetupWrapper {
|
||||
return inject_impl(tokens, fn)();
|
||||
};
|
||||
}
|
||||
|
||||
/** @deprecated {use async(withProviders().inject())} */
|
||||
injectAsync(tokens: any[], fn: Function): Function {
|
||||
return () => {
|
||||
this._addProviders();
|
||||
return injectAsync_impl(tokens, fn)();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function withProviders(providers: () => any) {
|
||||
return new InjectSetupWrapper(providers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated {use async(inject())}
|
||||
*
|
||||
* Allows injecting dependencies in `beforeEach()` and `it()`. The test must return
|
||||
* a promise which will resolve when all asynchronous activity is complete.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* it('...', injectAsync([AClass], (object) => {
|
||||
* return object.doSomething().then(() => {
|
||||
* expect(...);
|
||||
* });
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
export function injectAsync(tokens: any[], fn: Function): Function {
|
||||
return async(inject(tokens, fn));
|
||||
}
|
||||
|
||||
// This is to ensure inject(Async) within InjectSetupWrapper doesn't call itself
|
||||
// when transpiled to Dart.
|
||||
var inject_impl = inject;
|
||||
var injectAsync_impl = injectAsync;
|
||||
|
@ -12,9 +12,7 @@
|
||||
*/
|
||||
import {isPromise, isString} from '../src/facade/lang';
|
||||
|
||||
import {TestInjector, async, getTestInjector, inject, injectAsync} from './test_injector';
|
||||
|
||||
export {async, inject, injectAsync} from './test_injector';
|
||||
import {TestInjector, getTestInjector} from './test_injector';
|
||||
|
||||
declare var global: any;
|
||||
|
||||
@ -79,6 +77,8 @@ var jsmIt = _global.it;
|
||||
var jsmIIt = _global.fit;
|
||||
var jsmXIt = _global.xit;
|
||||
|
||||
// TODO(juliemr): override the globals and make them throw with a useful message.
|
||||
|
||||
var testInjector: TestInjector = getTestInjector();
|
||||
|
||||
// Reset the test providers before each test.
|
||||
|
@ -18,6 +18,9 @@ export {MockAnimationPlayer} from './animation/mock_animation_player';
|
||||
export {AsyncTestCompleter} from './async_test_completer';
|
||||
export {inject} from './test_injector';
|
||||
export {expect} from './testing';
|
||||
export * from './logger';
|
||||
export * from './ng_zone_mock';
|
||||
export * from './mock_application_ref';
|
||||
|
||||
export var proxy: ClassDecorator = (t: any /** TODO #9100 */) => t;
|
||||
|
||||
|
Reference in New Issue
Block a user