所以在Chai .deep.equals中允许一个按值比较数组,而.closeTo(和.approximately)允许一个人将浮点数与指定的精度进行比较。我在如何让它做两件事时都画了一个空白,即测试"关闭"一系列浮点数相等,例如
expect([0.1,0.2,0.34]).to.beDeeplyCloseTo([0.1,0.2,0.33333333]);
谢谢!
答案 0 :(得分:0)
var chai = require("chai");
var chaiDeepCloseTo = require("chai-deep-closeto");
chai.use(chaiDeepCloseTo);
expect([ 1.00001, [ 2.00001, 3.00001 ], 4.00001 ])
.to.be.deep.closeTo([ 1, [ 2, 3 ], 4 ], 1e-4);