Skip to content

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

@benjamincburns

Description

@benjamincburns

🐛 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 [email protected].

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions