(Zone: ZoneType)
| 14 | declare let jest: any; |
| 15 | |
| 16 | export function patchJasmine(Zone: ZoneType): void { |
| 17 | Zone.__load_patch('jasmine', (global: any, Zone: ZoneType, api: _ZonePrivate) => { |
| 18 | const __extends = function (d: any, b: any) { |
| 19 | for (const p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; |
| 20 | function __(this: Object) { |
| 21 | this.constructor = d; |
| 22 | } |
| 23 | d.prototype = |
| 24 | b === null ? Object.create(b) : ((__.prototype = b.prototype), new (__ as any)()); |
| 25 | }; |
| 26 | // Patch jasmine's describe/it/beforeEach/afterEach functions so test code always runs |
| 27 | // in a testZone (ProxyZone). (See: angular/zone.js#91 & angular/angular#10503) |
| 28 | if (!Zone) throw new Error('Missing: zone.js'); |
| 29 | if (typeof jest !== 'undefined') { |
| 30 | // return if jasmine is a light implementation inside jest |
| 31 | // in this case, we are running inside jest not jasmine |
| 32 | return; |
| 33 | } |
| 34 | if (typeof jasmine == 'undefined' || (jasmine as any)['__zone_patch__']) { |
| 35 | return; |
| 36 | } |
| 37 | (jasmine as any)['__zone_patch__'] = true; |
| 38 | |
| 39 | const SyncTestZoneSpec: {new (name: string): ZoneSpec} = (Zone as any)['SyncTestZoneSpec']; |
| 40 | const ProxyZoneSpec: {new (): ZoneSpec} = (Zone as any)['ProxyZoneSpec']; |
| 41 | if (!SyncTestZoneSpec) throw new Error('Missing: SyncTestZoneSpec'); |
| 42 | if (!ProxyZoneSpec) throw new Error('Missing: ProxyZoneSpec'); |
| 43 | |
| 44 | const ambientZone = Zone.current; |
| 45 | |
| 46 | const symbol = Zone.__symbol__; |
| 47 | |
| 48 | // whether patch jasmine clock when in fakeAsync |
| 49 | const disablePatchingJasmineClock = global[symbol('fakeAsyncDisablePatchingClock')] === true; |
| 50 | // the original variable name fakeAsyncPatchLock is not accurate, so the name will be |
| 51 | // fakeAsyncAutoFakeAsyncWhenClockPatched and if this enablePatchingJasmineClock is false, we |
| 52 | // also automatically disable the auto jump into fakeAsync feature |
| 53 | const enableAutoFakeAsyncWhenClockPatched = |
| 54 | !disablePatchingJasmineClock && |
| 55 | (global[symbol('fakeAsyncPatchLock')] === true || |
| 56 | global[symbol('fakeAsyncAutoFakeAsyncWhenClockPatched')] === true); |
| 57 | |
| 58 | // Monkey patch all of the jasmine DSL so that each function runs in appropriate zone. |
| 59 | const jasmineEnv: any = jasmine.getEnv(); |
| 60 | ['describe', 'xdescribe', 'fdescribe'].forEach((methodName) => { |
| 61 | let originalJasmineFn: Function = jasmineEnv[methodName]; |
| 62 | jasmineEnv[methodName] = function (description: string, specDefinitions: Function) { |
| 63 | return originalJasmineFn.call( |
| 64 | this, |
| 65 | description, |
| 66 | wrapDescribeInZone(description, specDefinitions), |
| 67 | ); |
| 68 | }; |
| 69 | }); |
| 70 | ['it', 'xit', 'fit'].forEach((methodName) => { |
| 71 | let originalJasmineFn: Function = jasmineEnv[methodName]; |
| 72 | jasmineEnv[symbol(methodName)] = originalJasmineFn; |
| 73 | jasmineEnv[methodName] = function ( |
no test coverage detected