assert.{equal,strictEqual} do not print compared objects when comparing falsy values and message has been set
- Dominant language
- JavaScript
- Stars
- 1.9k
- Forks
- 359
- PR merge metrics
- No merged PRs in 30d
Description
This is the test module:
```
module.exports = {
'Falsy tests with messages': function(test) {
test.equal(1, undefined, "A message");
test.equal(1, null, "A message");
test.equal(1, false, "A message");
test.equal(1, 0, "A message");
test.equal(1, '', "A message");
test.done();
},
'Falsy tests without messages': function(test) {
test.equal(1, undefined);
test.equal(1, null);
test.equal(1, false);
test.equal(1, 0);
test.equal(1, '');
test.done();
}
};
```
And the output:
```
% nodeunit test.js |grep 'AssertionError\|Falsy'
✖ Falsy tests with messages
AssertionError: A message
AssertionError: A message
AssertionError: A message
AssertionError: A message
AssertionError: A message
✖ Falsy tests without messages
AssertionError: == 1
AssertionError: null == 1
AssertionError: false == 1
AssertionError: 0 == 1
AssertionError: "" == 1
```
The problem is in [utils.betterErrors, line 186](https://github.com/caolan/nodeunit/blob/master/lib/utils.js#L186). I think equal, strictEqual and friends should set a property indicating that they have indeed been passed expected and actual values instead of trying to guess.
BTW, undefined should probably print "undefined" or something like that. And it also is strange that, compared to equal, the expected and actual values order is reversed.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at lib/utils.js around betterErrors, line 186, and reproduce the issue with the JavaScript test module shown in the report. Compare failures with and without messages for falsy values, including undefined. Done means the assertion output consistently includes the compared values and has clear expected/actual ordering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100