* Gets a function wrapping the body of a jest `it/beforeEach/afterEach` block to * execute in a ProxyZone zone. * This will run in the `proxyZone`.
(testBody: Function, isTestFunc = false)
| 75 | * This will run in the `proxyZone`. |
| 76 | */ |
| 77 | function wrapTestInZone(testBody: Function, isTestFunc = false): Function { |
| 78 | if (typeof testBody !== 'function') { |
| 79 | return testBody; |
| 80 | } |
| 81 | const wrappedFunc = function () { |
| 82 | if ( |
| 83 | (Zone as any)[api.symbol('useFakeTimersCalled')] === true && |
| 84 | testBody && |
| 85 | !(testBody as any).isFakeAsync |
| 86 | ) { |
| 87 | // jest.useFakeTimers is called, run into fakeAsyncTest automatically. |
| 88 | const fakeAsyncModule = (Zone as any)[Zone.__symbol__('fakeAsyncTest')]; |
| 89 | if (fakeAsyncModule && typeof fakeAsyncModule.fakeAsync === 'function') { |
| 90 | testBody = fakeAsyncModule.fakeAsync(testBody); |
| 91 | } |
| 92 | } |
| 93 | proxyZoneSpec.isTestFunc = isTestFunc; |
| 94 | return proxyZone.run(testBody, null, arguments as any); |
| 95 | }; |
| 96 | // Update the length of wrappedFunc to be the same as the length of the testBody |
| 97 | // So jest core can handle whether the test function has `done()` or not correctly |
| 98 | Object.defineProperty(wrappedFunc, 'length', { |
| 99 | configurable: true, |
| 100 | writable: true, |
| 101 | enumerable: false, |
| 102 | }); |
| 103 | wrappedFunc.length = testBody.length; |
| 104 | return wrappedFunc; |
| 105 | } |
| 106 | |
| 107 | ['describe', 'xdescribe', 'fdescribe'].forEach((methodName) => { |
| 108 | let originalJestFn: Function = context[methodName]; |
no outgoing calls
no test coverage detected
searching dependent graphs…