Skip to content

Commit

Permalink
update error message for closeTo
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Oct 8, 2024
1 parent 5abacf4 commit 45f8825
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3026,7 +3026,11 @@ function closeTo(expected, delta, msg) {
, ssfi = flag(this, 'ssfi');

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);
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);
new Assertion(expected, flagMsg, ssfi, true).is.numeric;

const abs = (x) => x < 0n ? -x : x;
Expand Down
4 changes: 2 additions & 2 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ describe('assert', function () {

err(function() {
assert.closeTo(1.5, 1.0, undefined, 'blah');
}, "blah: expected undefined to be numeric");
}, "blah: A `delta` value is required for `closeTo`");
});

it('approximately', function(){
Expand Down Expand Up @@ -1947,7 +1947,7 @@ describe('assert', function () {

err(function() {
assert.approximately(1.5, 1.0, undefined, 'blah');
}, "blah: expected undefined to be numeric");
}, "blah: A `delta` value is required for `closeTo`");
});

it('sameMembers', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3306,7 +3306,7 @@ describe('expect', function () {

err(function() {
expect(1.5, 'blah').to.be.closeTo(1.0);
}, "blah: expected undefined to be numeric");
}, "blah: A `delta` value is required for `closeTo`");
});

it('approximately', function(){
Expand Down Expand Up @@ -3336,7 +3336,7 @@ describe('expect', function () {

err(function() {
expect(1.5).to.be.approximately(1.0);
}, "expected undefined to be numeric");
}, "A `delta` value is required for `closeTo`");
});

it('oneOf', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -2768,7 +2768,7 @@ describe('should', function() {

err(function() {
(1.5).should.be.closeTo(1.0, undefined, 'blah');
}, "blah: expected undefined to be numeric");
}, "blah: A `delta` value is required for `closeTo`");
});

it('approximately', function(){
Expand All @@ -2792,7 +2792,7 @@ describe('should', function() {

err(function() {
(1.5).should.be.approximately(1.0);
}, "expected undefined to be numeric");
}, "A `delta` value is required for `closeTo`");
});

it('include.members', function() {
Expand Down

0 comments on commit 45f8825

Please sign in to comment.