Skip to content

Commit

Permalink
Use home-made abs to support BigInt in approximately
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Feb 20, 2024
1 parent f78345a commit 976ad08
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
1 change: 1 addition & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 976ad08

Please sign in to comment.