(
matcherName: string,
matcher: RawMatcherFn,
isNot: boolean,
actual: Promise<any> | (() => Promise<any>),
outerErr: JestAssertionError,
)
| 162 | |
| 163 | const makeResolveMatcher = |
| 164 | ( |
| 165 | matcherName: string, |
| 166 | matcher: RawMatcherFn, |
| 167 | isNot: boolean, |
| 168 | actual: Promise<any> | (() => Promise<any>), |
| 169 | outerErr: JestAssertionError, |
| 170 | ): PromiseMatcherFn => |
| 171 | (...args) => { |
| 172 | const options = { |
| 173 | isNot, |
| 174 | promise: 'resolves', |
| 175 | }; |
| 176 | |
| 177 | const actualWrapper: Promise<any> = |
| 178 | typeof actual === 'function' ? actual() : actual; |
| 179 | |
| 180 | if (!isPromise(actualWrapper)) { |
| 181 | throw new JestAssertionError( |
| 182 | matcherUtils.matcherErrorMessage( |
| 183 | matcherUtils.matcherHint(matcherName, undefined, '', options), |
| 184 | `${matcherUtils.RECEIVED_COLOR( |
| 185 | 'received', |
| 186 | )} value must be a promise or a function returning a promise`, |
| 187 | matcherUtils.printWithType( |
| 188 | 'Received', |
| 189 | actual, |
| 190 | matcherUtils.printReceived, |
| 191 | ), |
| 192 | ), |
| 193 | ); |
| 194 | } |
| 195 | |
| 196 | const innerErr = new JestAssertionError(); |
| 197 | |
| 198 | return actualWrapper.then( |
| 199 | result => |
| 200 | makeThrowingMatcher(matcher, isNot, 'resolves', result, innerErr).apply( |
| 201 | null, |
| 202 | args, |
| 203 | ), |
| 204 | error => { |
| 205 | outerErr.message = |
| 206 | `${matcherUtils.matcherHint( |
| 207 | matcherName, |
| 208 | undefined, |
| 209 | '', |
| 210 | options, |
| 211 | )}\n\n` + |
| 212 | 'Received promise rejected instead of resolved\n' + |
| 213 | `Rejected to value: ${matcherUtils.printReceived(error)}`; |
| 214 | throw outerErr; |
| 215 | }, |
| 216 | ); |
| 217 | }; |
| 218 | |
| 219 | const makeRejectMatcher = |
| 220 | ( |
no test coverage detected