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

Clearer messages for Node assert errors #8792

Merged
merged 2 commits into from
Aug 10, 2019

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Aug 7, 2019

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) or assert.ok(condition), the extra output is confusing because it starts by referring to assert.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 or assert.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.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good! Could you update the changelog?

@SimenB SimenB merged commit 384fe4a into jestjs:master Aug 10, 2019
@Zalathar Zalathar deleted the clearer-node-assert-errors branch August 11, 2019 00:08
jeysal added a commit to felipepastorelima/jest that referenced this pull request Aug 11, 2019
* upstream/master:
  expect: Display equal values for ReturnedWith similar to CalledWith (jestjs#8791)
  Clearer messages for Node assert errors (jestjs#8792)
  use babel-plugin-replace-ts-export-assignment package (jestjs#8805)
  jest-matcher-utils: Add color options to matcherHint (jestjs#8795)
  chore: Make sure copyright header comment includes license (jestjs#8783)
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants