-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(testing/asserts): return error from assertRejects
and assertThrows
#2226
feat(testing/asserts): return error from assertRejects
and assertThrows
#2226
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not on the core team, just another contributor. Giving my feedback because I worked in this area before and think the change in call signature issue is a good opportunity to also fix another issue related to assertThrows
and assertRejects
.
@@ -22,7 +22,7 @@ function slidingWindowsThrowsTest<T>( | |||
size: number, | |||
config?: { step?: number; partial?: boolean }, | |||
], | |||
ErrorClass?: ErrorConstructor | undefined, | |||
ErrorClass: ErrorConstructor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it to required, because none of the signatures of assertThrows
function matches the way this function is called. I'm open to refactoring it to keep it optional though. It can be something like:
if (ErrorClass) {
assertThrows(
() => {
slidingWindows(...input);
},
ErrorClass,
msgIncludes,
msg,
);
} else {
assertThrows(
() => {
slidingWindows(...input);
},
msg,
);
}
@@ -641,66 +641,86 @@ export function assertIsError<E extends Error = Error>( | |||
* callback which will be passed the error, usually to apply some custom | |||
* assertions on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was thinking to remove this bit about error callback from the documentation not to encourage developers to use it, because we're deprecating this parameter. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrkldshv LGTM. Nice work!
Note: This is going to be a breaking change in 2 points.
|
Makes
assertRejects
andassertThrows
return caught error.assertRejects
andassertThrows
signaturesCloses #1362, #2220.