/** * @license * Copyright Google LLC 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 */ /** * Wraps a test function in an asynchronous test zone. The test will automatically * complete when all asynchronous calls within this zone are done. Can be used * to wrap an {@link inject} call. * * Example: * * ``` * it('...', waitForAsync(inject([AClass], (object) => { * object.doSomething.then(() => { * expect(...); * }) * }); * ``` * * @publicApi */ export function waitForAsync(fn) { const _Zone = typeof Zone !== 'undefined' ? Zone : null; if (!_Zone) { return function () { return Promise.reject('Zone is needed for the waitForAsync() test helper but could not be found. ' + 'Please make sure that your environment includes zone.js'); }; } const asyncTest = _Zone && _Zone[_Zone.__symbol__('asyncTest')]; if (typeof asyncTest === 'function') { return asyncTest(fn); } return function () { return Promise.reject('zone-testing.js is needed for the async() test helper but could not be found. ' + 'Please make sure that your environment includes zone.js/testing'); }; } /** * @deprecated use `waitForAsync()`, (expected removal in v12) * @see {@link waitForAsync} * @publicApi * */ export function async(fn) { return waitForAsync(fn); } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXN5bmMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb3JlL3Rlc3Rpbmcvc3JjL2FzeW5jLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUNIOzs7Ozs7Ozs7Ozs7Ozs7O0dBZ0JHO0FBQ0gsTUFBTSxVQUFVLFlBQVksQ0FBQyxFQUFZO0lBQ3ZDLE1BQU0sS0FBSyxHQUFRLE9BQU8sSUFBSSxLQUFLLFdBQVcsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUM7SUFDN0QsSUFBSSxDQUFDLEtBQUssRUFBRTtRQUNWLE9BQU87WUFDTCxPQUFPLE9BQU8sQ0FBQyxNQUFNLENBQ2pCLDRFQUE0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