| 38 | return caughtError; |
| 39 | }, |
| 40 | async toRejectWith(message: string): Promise<Error> { |
| 41 | let caughtError: unknown; |
| 42 | let resolved; |
| 43 | let rejected = false; |
| 44 | try { |
| 45 | resolved = await maybePromise; |
| 46 | } catch (error) { |
| 47 | rejected = true; |
| 48 | caughtError = error; |
| 49 | } |
| 50 | |
| 51 | assert( |
| 52 | rejected, |
| 53 | `Promise should have rejected with message '${message}', but resolved as '${inspect( |
| 54 | resolved, |
| 55 | )}'`, |
| 56 | ); |
| 57 | |
| 58 | expect(caughtError).to.be.an.instanceOf(Error); |
| 59 | expect(caughtError).to.have.property('message', message); |
| 60 | return caughtError as Error; |
| 61 | }, |
| 62 | }; |
| 63 | } |