MCPcopy Index your code
hub / github.com/angular/angular / wrapTestInZone

Function wrapTestInZone

packages/zone.js/lib/jest/jest.ts:77–105  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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];

Callers 2

wrapTestFactoryInZoneFunction · 0.70
patchJestFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…