我有一个mocha / chai断言给我一个错误,尽管值是相同的
测试代码在这里:
describe("Util.SplitNumAndOper Tests", function(){
it('should have "6+4+3" return [6,"+",4,"+",3]', function(){
let a = util.splitNumAndOper("6+4+3");
assert.equal(a,[6,'+',4,'+',3]);
})
})
这里发生了什么?
答案 0 :(得分:0)
.equal(actual, expected, [message])方法断言实际和预期的非严格相等性(==
)
.deepEqual(actual, expected, [message])断言实际与预期完全相同
在您的情况下,actual
和expected
的值均为Array
,它们引用不同的数组。它们在内存中具有不同的指针。因此.equal
将失败。
import { assert } from "chai";
describe("Util.SplitNumAndOper Tests", function(){
it('should have "6+4+3" return [6,"+",4,"+",3]', function(){
const a = [6,'+',4,'+',3];
assert.equal(a,[6,'+',4,'+',3]);
})
})
单元测试结果:
Util.SplitNumAndOper Tests
✓ should have "6+4+3" return [6,"+",4,"+",3]
1 passing (75ms)