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

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

Closed
benjamincburns opened this issue Nov 5, 2019 · 5 comments

Comments

@benjamincburns
Copy link

benjamincburns commented Nov 5, 2019

🐛 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
@benjamincburns benjamincburns changed the title Default reporter should only print AssertionError message when no operator specified Default reporter shouldn't show expected vs actual on AssertionError when assert.fail called Nov 5, 2019
@benjamincburns benjamincburns changed the title Default reporter shouldn't show expected vs actual on AssertionError when assert.fail called Default reporter shouldn't print expected vs actual values when assert.fail called Nov 5, 2019
@leonardovillela
Copy link
Contributor

Can i take this issue?

@leonardovillela
Copy link
Contributor

leonardovillela commented Dec 14, 2019

Already resolved this problem by PR: #9262. This issue can be closed.

@SimenB
Copy link
Member

SimenB commented Dec 14, 2019

Thanks!

@SimenB SimenB closed this as completed Dec 14, 2019
@github-actions
Copy link

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.

@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

No branches or pull requests

3 participants