Skip to content

Commit

Permalink
explicitly allow a delta of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Oct 9, 2024
1 parent 45f8825 commit 0005660
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3027,10 +3027,10 @@ function closeTo(expected, delta, msg) {

new Assertion(obj, flagMsg, ssfi, true).is.numeric;
let message = 'A `delta` value is required for `closeTo`';
if (!delta) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi);
if (delta == undefined) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi);
new Assertion(delta, flagMsg, ssfi, true).is.numeric;
message = 'A `expected` value is required for `closeTo`';
if (!delta) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi);
if (expected == undefined) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi);
new Assertion(expected, flagMsg, ssfi, true).is.numeric;

const abs = (x) => x < 0n ? -x : x;
Expand Down
1 change: 1 addition & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,7 @@ describe('assert', function () {
assert.closeTo(1.5, 1.0, 0.5);
assert.closeTo(10, 20, 20);
assert.closeTo(-10, 20, 30);
assert.closeTo(10, 10, 0);

err(function(){
assert.closeTo(2, 1.0, 0.5, 'blah');
Expand Down

0 comments on commit 0005660

Please sign in to comment.