-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
t.throws()
and t.throwsAsync()
require the resulting exception to be a proper error:
Lines 147 to 154 in 952a017
if (!isError(actual)) { | |
throw new AssertionError({ | |
assertion, | |
message, | |
savedError, | |
values: [formatWithLabel(`${prefix} exception that is not an error:`, actual)] | |
}); | |
} |
I propose we add an any: boolean
option to the expectations
object used for these assertions. If true
it won't cause a failed assertion when the exception is not an error.
We need to update the validation logic here to allow this property:
Line 74 in 952a017
function validateExpectations(assertion, expectations, numberArgs) { // eslint-disable-line complexity |
Don't forget to update the type definition:
Line 11 in 952a017
export type ThrowsExpectation = { |
If any
is true
, we should try and change the typing of the return value to be unknown
:
Line 252 in 952a017
<ThrownError extends Error>(fn: () => any, expectations?: ThrowsExpectation | null, message?: string): ThrownError; |
Line 263 in 952a017
<ThrownError extends Error>(fn: () => PromiseLike<any>, expectations?: null, message?: string): Promise<ThrownError>; |
And update our own tests:
Line 786 in 952a017
test('.throws()', gather(t => { |
Line 976 in 952a017
test('.throwsAsync()', gather(t => { |
See also the discussion in #1841.