Fix toBeCloseTo matcher for Node.js 12 and Chrome 74
This commit is contained in:
@@ -90,4 +90,18 @@ describe("toBeCloseTo", function() {
|
|||||||
result = matcher.compare(1.23, 1.234);
|
result = matcher.compare(1.23, 1.234);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("handles edge cases with rounding", function () {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||||
|
result;
|
||||||
|
|
||||||
|
// these cases resulted in false negatives in version of V8
|
||||||
|
// included in Node.js 12 and Chrome 74 (and Edge Chromium)
|
||||||
|
result = matcher.compare(4.030904708957288, 4.0309, 5);
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
result = matcher.compare(4.82665525779431,4.82666, 5);
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
result = matcher.compare(-2.82665525779431, -2.82666, 5);
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ getJasmineRequireObj().toBeCloseTo = function() {
|
|||||||
var maxDelta = Math.pow(10, -precision) / 2;
|
var maxDelta = Math.pow(10, -precision) / 2;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pass: Math.round(delta * pow) / pow <= maxDelta
|
pass: Math.round(delta * pow) <= maxDelta * pow
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user