assert.{equal,strictEqual} do not print compared objects when comparing falsy values and message has been set
- 主要语言
- JavaScript
- 星标
- 1.9k
- 派生
- 359
- PR 合并指标
- 30 天内没有已合并 PR
描述
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.
贡献指南
这个仓库没有索引到贡献指南
调研方向
从 lib/utils.js 中 betterErrors 附近的第 186 行开始,使用报告中所示的 JavaScript 测试模块重现该问题。比较 falsy 值(包括 undefined)在有消息和无消息时的失败情况。完成的标准是,断言输出始终包含被比较的值,并且 expected/actual 顺序清晰。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- testing-qa
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100