(
matcherName: string,
matcher: RawMatcherFn,
isNot: boolean,
actual: Promise<any> | (() => Promise<any>),
outerErr: JestAssertionError,
)
| 218 | |
| 219 | const makeRejectMatcher = |
| 220 | ( |
| 221 | matcherName: string, |
| 222 | matcher: RawMatcherFn, |
| 223 | isNot: boolean, |
| 224 | actual: Promise<any> | (() => Promise<any>), |
| 225 | outerErr: JestAssertionError, |
| 226 | ): PromiseMatcherFn => |
| 227 | (...args) => { |
| 228 | const options = { |
| 229 | isNot, |
| 230 | promise: 'rejects', |
| 231 | }; |
| 232 | |
| 233 | const actualWrapper: Promise<any> = |
| 234 | typeof actual === 'function' ? actual() : actual; |
| 235 | |
| 236 | if (!isPromise(actualWrapper)) { |
| 237 | throw new JestAssertionError( |
| 238 | matcherUtils.matcherErrorMessage( |
| 239 | matcherUtils.matcherHint(matcherName, undefined, '', options), |
| 240 | `${matcherUtils.RECEIVED_COLOR( |
| 241 | 'received', |
| 242 | )} value must be a promise or a function returning a promise`, |
| 243 | matcherUtils.printWithType( |
| 244 | 'Received', |
| 245 | actual, |
| 246 | matcherUtils.printReceived, |
| 247 | ), |
| 248 | ), |
| 249 | ); |
| 250 | } |
| 251 | |
| 252 | const innerErr = new JestAssertionError(); |
| 253 | |
| 254 | return actualWrapper.then( |
| 255 | result => { |
| 256 | outerErr.message = |
| 257 | `${matcherUtils.matcherHint( |
| 258 | matcherName, |
| 259 | undefined, |
| 260 | '', |
| 261 | options, |
| 262 | )}\n\n` + |
| 263 | 'Received promise resolved instead of rejected\n' + |
| 264 | `Resolved to value: ${matcherUtils.printReceived(result)}`; |
| 265 | throw outerErr; |
| 266 | }, |
| 267 | error => |
| 268 | makeThrowingMatcher(matcher, isNot, 'rejects', error, innerErr).apply( |
| 269 | null, |
| 270 | args, |
| 271 | ), |
| 272 | ); |
| 273 | }; |
| 274 | |
| 275 | const makeThrowingMatcher = ( |
| 276 | matcher: RawMatcherFn, |
no test coverage detected