(
fn: Function,
context: any,
applyArgs: unknown[] | undefined,
finishCallback: Function,
failCallback: Function,
)
| 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 | ); |
| 284 | } |
| 285 | const ProxyZoneSpec = (Zone as any)['ProxyZoneSpec'] as { |
| 286 | get(): {setDelegate(spec: ZoneSpec): void; getDelegate(): ZoneSpec}; |
| 287 | assertPresent: () => void; |
| 288 | }; |
| 289 | if (!ProxyZoneSpec) { |
| 290 | throw new Error( |
| 291 | 'ProxyZoneSpec is needed for the async() test helper but could not be found. ' + |
| 292 | 'Please make sure that your environment includes zone.js/plugins/proxy', |
| 293 | ); |
| 294 | } |
| 295 | const proxyZoneSpec = ProxyZoneSpec.get(); |
| 296 | ProxyZoneSpec.assertPresent(); |
| 297 | // We need to create the AsyncTestZoneSpec outside the ProxyZone. |
| 298 | // If we do it in ProxyZone then we will get to infinite recursion. |
| 299 | const proxyZone = Zone.current.getZoneWith('ProxyZoneSpec'); |
| 300 | const previousDelegate = proxyZoneSpec.getDelegate(); |
| 301 | proxyZone!.parent!.run(() => { |
| 302 | const testZoneSpec: ZoneSpec = new AsyncTestZoneSpec( |
| 303 | () => { |
| 304 | // Need to restore the original zone. |
| 305 | if (proxyZoneSpec.getDelegate() == testZoneSpec) { |
| 306 | // Only reset the zone spec if it's |
| 307 | // still this one. Otherwise, assume |
| 308 | // it's OK. |
| 309 | proxyZoneSpec.setDelegate(previousDelegate); |
| 310 | } |
| 311 | (testZoneSpec as any).unPatchPromiseForTest(); |
| 312 | currentZone.run(() => { |
| 313 | finishCallback(); |
| 314 | }); |
| 315 | }, |
| 316 | (error: any) => { |
| 317 | // Need to restore the original zone. |
| 318 | if (proxyZoneSpec.getDelegate() == testZoneSpec) { |
| 319 | // Only reset the zone spec if it's sill this one. Otherwise, assume it's OK. |
| 320 | proxyZoneSpec.setDelegate(previousDelegate); |
| 321 | } |
| 322 | (testZoneSpec as any).unPatchPromiseForTest(); |
| 323 | currentZone.run(() => { |
| 324 | failCallback(error); |
| 325 | }); |
| 326 | }, |
| 327 | 'test', |
no test coverage detected
searching dependent graphs…