question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default reporter shouldn't print expected vs actual values when assert.fail called

See original GitHub issue

🐛 Bug Report

When using the builtin assert library, a call to assert.fail causes Jest to render the test failure as if strictEqual were called, showing an expected value of undefined and an actual value of undefined.

This is confusing because it seems like a strictEqual check is failing when it shouldn’t be, as the expected and actual values are the same. In reality no equality check is being performed. Further, the method signature that the test reporter defaults to (assert.fail(received, expected)) has been deprecated.

I ran into this issue on jest@24.9.0.

To Reproduce

Steps to reproduce the behavior:

The following test reproduces the behavior. I’ve also created a repl.it demo illustrating the issue.

const assert = require("assert").strict;

test("example", () => {
    assert.fail("This prints an unexpected failure description.")
});

This produces the following output:

 FAIL  sample.ts
  ✕ example (3ms)

  ● example

    assert.fail(received, expected)

    Expected value fail to:
      undefined
    Received:
      undefined
    
    Message:
      This prints an unexpected failure description.

    Difference:

    Compared values have no visual difference.

      2 | 
      3 | test("example", () => {
    > 4 |     assert.fail("This prints an unexpected failure description.")
        |            ^
      5 | });

      at Object.<anonymous> (sample.js:4:12)

I get this output when I manually throw an `AssertionError` and set the operator to `fail` as well.

Expected behavior

I’d expect output something like the following:

 FAIL  sample.ts
  ✕ example (3ms)

  ● example

    assert.fail(message)
    
    Message:
      This prints an unexpected failure description.

      2 | 
      3 | test("example", () => {
    > 4 |     assert.fail("This prints an unexpected failure description.")
        |            ^
      5 | });

      at Object.<anonymous> (sample.js:4:12)

envinfo

  System:
    OS: macOS 10.15
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 12.11.1 - ~/.nvm/versions/node/v12.11.1/bin/node
    Yarn: 1.19.1 - ~/.nvm/versions/node/v12.11.1/bin/yarn
    npm: 6.11.3 - ~/.nvm/versions/node/v12.11.1/bin/npm

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Dec 14, 2019

Thanks!

0reactions
github-actions[bot]commented, May 11, 2021

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. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Print message on expect() assert failure - Stack Overflow
In general I think I'd discourage a custom matcher without being sure you're covering all the bases with it, but in this case...
Read more >
Python's assert: Debug and Test Your Code Like a Pro
In this tutorial, you'll learn how to use Python's assert statement to document, debug, and test code in development.
Read more >
Assertion Styles - Chai
Assertion Styles. This section of the guide introduces you to the three different assertion styles that you may use in your testing environment....
Read more >
Changelog - testthat
Failing expectations now include a backtrace when they're not called directly from within test_that() but are instead wrapped in some helper ...
Read more >
Mocha documentation — DevDocs
Mocha validates any custom reporters or interfaces which were loaded via --require ... expected and actual values when an assertion failure is encountered....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found