Clearer messages for Node assert errors #8792
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When a test throws an AssertionError from Node's
assert
module, Jest tries to use the information in that exception to display a more informative error message.However, for errors thrown by
assert(condition)
orassert.ok(condition)
, the extra output is confusing because it starts by referring toassert.equal(received, expected)
, which makes the failure harder to understand.This PR tries to detect when the exception was probably thrown by a plain
assert
orassert.ok
call, and simplifies the enhanced output in that case, so that it is easier for the user to understand what actually caused the test to fail.Test plan
The existing output is already covered by
e2e/__tests__/failures.test.ts
, so this PR updates the corresponding snapshot.