diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index c22ba417..c4da00c1 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -3013,8 +3013,10 @@ function closeTo(expected, delta, msg) { new Assertion(delta, flagMsg, ssfi, true).is.numeric; new Assertion(expected, flagMsg, ssfi, true).is.numeric; + const abs = (x) => x < 0n ? -x : x; + this.assert( - Math.abs(obj - expected) <= delta + abs(obj - expected) <= delta , 'expected #{this} to be close to ' + expected + ' +/- ' + delta , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta ); diff --git a/test/assert.js b/test/assert.js index 5ab8ca8f..747b2719 100644 --- a/test/assert.js +++ b/test/assert.js @@ -1877,6 +1877,7 @@ describe('assert', function () { assert.approximately(1.5, 1.0, 0.5); assert.approximately(10, 20, 20); assert.approximately(-10, 20, 30); + assert.approximately(1n, 2n, 1n); err(function(){ assert.approximately(2, 1.0, 0.5, 'blah');