| 102 | } |
| 103 | |
| 104 | export function throws(thunk: () => void, error?: string | Error | ((u: unknown) => undefined), ..._: Array<never>) { |
| 105 | try { |
| 106 | thunk() |
| 107 | } catch (e) { |
| 108 | if (error !== undefined) { |
| 109 | if (Predicate.isString(error)) { |
| 110 | assertInstanceOf(e, Error) |
| 111 | strictEqual(e.message, error) |
| 112 | } else if (Predicate.isError(error)) { |
| 113 | deepStrictEqual(e, error) |
| 114 | } else { |
| 115 | error(e) |
| 116 | } |
| 117 | } |
| 118 | return |
| 119 | } |
| 120 | fail("Expected to throw an error") |
| 121 | } |
| 122 | |
| 123 | export async function throwsAsync( |
| 124 | thunk: () => Promise<void>, |