-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Bug]: assert.throws
errors always formatted as not thrown
#13264
Comments
Ah, good catch! That's a bug in how we format PR very much welcome fixing! The code is here https://github.com/facebook/jest/blob/e703e6ed1861595d56e25a764642da5a32b32c5a/packages/jest-circus/src/formatNodeAssertErrors.ts#L152-L160 and here https://github.com/facebook/jest/blob/e703e6ed1861595d56e25a764642da5a32b32c5a/packages/jest-jasmine2/src/assertionErrorMessage.ts#L113-L121 (Might be a good idea as part of this to share that code somehow, but definitely not needed!) And the current test is here https://github.com/facebook/jest/blob/e703e6ed1861595d56e25a764642da5a32b32c5a/e2e/failures/__tests__/assertionError.test.js#L75-L77 |
I would like to work on this issue |
Awesome, go for it! |
assert.throws
errors always formatted as not thrown
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Version
29.0.3
Steps to reproduce
Expected behavior
When Node's
assert.throws()
assertion error is caught and reported by Jest, it should report the original error message, or at least report an accurate error message.Actual behavior
Jest will always report an
assert.throws()
error with the following message:Additional context
The reproducible example contains two test cases. The first will cause
assert.throws()
to fail because themessage
property contains the incorrect content. The second will causeassert.throws()
to fail because the wrong error class was thrown. In both cases, you'll find that Jest will report the error as "Expected the function to throw an error. But it didn't throw anything". To proove that Jest is incorrectly reporting the error, I've also caught and logged out these assertion errors. You can find the logged errors above the Jest output. There, you'll find accurate output such as:and
Environment
System: OS: Linux 5.19 Fedora Linux 36 (Workstation Edition) CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz Binaries: Node: 16.14.0 - /usr/bin/node npm: 8.3.1 - /usr/bin/npm npmPackages: jest: ^29.0.3 => 29.0.3
The text was updated successfully, but these errors were encountered: