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:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Thanks!
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.