(Zone: ZoneType)
| 224 | } |
| 225 | |
| 226 | export function patchAsyncTest(Zone: ZoneType): void { |
| 227 | // Export the class so that new instances can be created with proper |
| 228 | // constructor params. |
| 229 | (Zone as any)['AsyncTestZoneSpec'] = AsyncTestZoneSpec; |
| 230 | |
| 231 | Zone.__load_patch('asynctest', (global: any, Zone: ZoneType, api: _ZonePrivate) => { |
| 232 | /** |
| 233 | * Wraps a test function in an asynchronous test zone. The test will automatically |
| 234 | * complete when all asynchronous calls within this zone are done. |
| 235 | */ |
| 236 | (Zone as any)[api.symbol('asyncTest')] = function asyncTest(fn: Function): (done: any) => any { |
| 237 | // If we're running using the Jasmine test framework, adapt to call the 'done' |
| 238 | // function when asynchronous activity is finished. |
| 239 | if (global.jasmine) { |
| 240 | // Not using an arrow function to preserve context passed from call site |
| 241 | return function (this: unknown, done: any) { |
| 242 | if (!done) { |
| 243 | // if we run beforeEach in @angular/core/testing/testing_internal then we get no done |
| 244 | // fake it here and assume sync. |
| 245 | done = function () {}; |
| 246 | done.fail = function (e: any) { |
| 247 | throw e; |
| 248 | }; |
| 249 | } |
| 250 | runInTestZone(fn, this, undefined, done, (err: any) => { |
| 251 | if (typeof err === 'string') { |
| 252 | return done.fail(new Error(err)); |
| 253 | } else { |
| 254 | done.fail(err); |
| 255 | } |
| 256 | }); |
| 257 | }; |
| 258 | } |
| 259 | // Otherwise, return a promise which will resolve when asynchronous activity |
| 260 | // is finished. This will be correctly consumed by the Mocha framework with |
| 261 | // it('...', async(myFn)); or can be used in a custom framework. |
| 262 | // Not using an arrow function to preserve context passed from call site |
| 263 | return function (this: unknown, ...args: unknown[]) { |
| 264 | return new Promise<void>((finishCallback, failCallback) => { |
| 265 | runInTestZone(fn, this, args, finishCallback, failCallback); |
| 266 | }); |
| 267 | }; |
| 268 | }; |
| 269 | |
| 270 | function runInTestZone( |
| 271 | fn: Function, |
| 272 | context: any, |
| 273 | applyArgs: unknown[] | undefined, |
| 274 | finishCallback: Function, |
| 275 | failCallback: Function, |
| 276 | ) { |
| 277 | const currentZone = Zone.current; |
| 278 | const AsyncTestZoneSpec = (Zone as any)['AsyncTestZoneSpec']; |
| 279 | if (AsyncTestZoneSpec === undefined) { |
| 280 | throw new Error( |
| 281 | 'AsyncTestZoneSpec is needed for the async() test helper but could not be found. ' + |
| 282 | 'Please make sure that your environment includes zone.js/plugins/async-test', |
| 283 | ); |
no test coverage detected
searching dependent graphs…