| 154 | extraError.stack = originalExtraErrorStack; |
| 155 | |
| 156 | const asyncJestTest = function (done: DoneFn) { |
| 157 | const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn; |
| 158 | const returnValue = wrappedFn.call({}, doneFnNoop); |
| 159 | |
| 160 | if (isPromise(returnValue)) { |
| 161 | returnValue.then(done.bind(null, null), (error: Error) => { |
| 162 | const {isError: checkIsError, message} = isError(error); |
| 163 | |
| 164 | if (message) { |
| 165 | extraError.message = message; |
| 166 | extraError.stack = |
| 167 | originalExtraErrorStack && |
| 168 | originalExtraErrorStack.replace('Error: ', `Error: ${message}`); |
| 169 | } |
| 170 | |
| 171 | if (jasmine.Spec.isPendingSpecException(error)) { |
| 172 | env.pending(message!); |
| 173 | done(); |
| 174 | } else { |
| 175 | done.fail(checkIsError ? error : extraError); |
| 176 | } |
| 177 | }); |
| 178 | } else if (returnValue === undefined) { |
| 179 | done(); |
| 180 | } else { |
| 181 | done.fail( |
| 182 | new Error( |
| 183 | 'Jest: `it` and `test` must return either a Promise or undefined.', |
| 184 | ), |
| 185 | ); |
| 186 | } |
| 187 | }; |
| 188 | |
| 189 | return originalFn.call(env, specName, asyncJestTest, timeout); |
| 190 | }; |