Skip to content
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

fix(expect): improve the error message when nothing is thrown when ing toThrow #3979

Merged
merged 5 commits into from Sep 18, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/expect/src/jest-expect.ts
Expand Up @@ -519,12 +519,22 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
}
}
else {
let isThrow = false
try {
obj()
}
catch (err) {
isThrow = true
thrown = err
}

if (!isThrow && !isNot) {
const message = utils.flag(this, 'message') || 'expected function to throw an error, but it didn`t'
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
const error = {
showDiff: false,
}
throw new AssertionError(message, error, utils.flag(this, 'ssfi'))
}
}

if (typeof expected === 'function') {
Expand Down