Skip to content

Commit

Permalink
Merge pull request #1248 from eouw0o83hf/master
Browse files Browse the repository at this point in the history
Add delta message to closeTo() error
  • Loading branch information
astorije authored Apr 21, 2019
2 parents 1cededa + 6bfd2fd commit 6441f3d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion chai.js
Original file line number Diff line number Diff line change
Expand Up @@ -3311,8 +3311,9 @@ module.exports = function (chai, _) {
new Assertion(obj, flagMsg, ssfi, true).is.a('number');
if (typeof expected !== 'number' || typeof delta !== 'number') {
flagMsg = flagMsg ? flagMsg + ': ' : '';
var deltaMessage = delta === undefined ? ", and a delta is required" : "";
throw new AssertionError(
flagMsg + 'the arguments to closeTo or approximately must be numbers',
flagMsg + 'the arguments to closeTo or approximately must be numbers' + deltaMessage,
undefined,
ssfi
);
Expand Down
3 changes: 2 additions & 1 deletion lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2950,8 +2950,9 @@ module.exports = function (chai, _) {
new Assertion(obj, flagMsg, ssfi, true).is.a('number');
if (typeof expected !== 'number' || typeof delta !== 'number') {
flagMsg = flagMsg ? flagMsg + ': ' : '';
var deltaMessage = delta === undefined ? ", and a delta is required" : "";
throw new AssertionError(
flagMsg + 'the arguments to closeTo or approximately must be numbers',
flagMsg + 'the arguments to closeTo or approximately must be numbers' + deltaMessage,
undefined,
ssfi
);
Expand Down
8 changes: 8 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,10 @@ describe('assert', function () {
err(function() {
assert.closeTo(1.5, 1.0, true, 'blah');
}, "blah: the arguments to closeTo or approximately must be numbers");

err(function() {
assert.closeTo(1.5, 1.0, undefined, 'blah');
}, "blah: the arguments to closeTo or approximately must be numbers, and a delta is required");
});

it('approximately', function(){
Expand All @@ -1874,6 +1878,10 @@ describe('assert', function () {
err(function() {
assert.approximately(1.5, 1.0, true, 'blah');
}, "blah: the arguments to closeTo or approximately must be numbers");

err(function() {
assert.approximately(1.5, 1.0, undefined, 'blah');
}, "blah: the arguments to closeTo or approximately must be numbers, and a delta is required");
});

it('sameMembers', function() {
Expand Down
8 changes: 8 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3239,6 +3239,10 @@ describe('expect', function () {
err(function() {
expect(1.5, 'blah').to.be.closeTo(1.0, true);
}, "blah: the arguments to closeTo or approximately must be numbers");

err(function() {
expect(1.5, 'blah').to.be.closeTo(1.0);
}, "blah: the arguments to closeTo or approximately must be numbers, and a delta is required");
});

it('approximately', function(){
Expand All @@ -3265,6 +3269,10 @@ describe('expect', function () {
err(function() {
expect(1.5).to.be.approximately(1.0, true);
}, "the arguments to closeTo or approximately must be numbers");

err(function() {
expect(1.5).to.be.approximately(1.0);
}, "the arguments to closeTo or approximately must be numbers, and a delta is required");
});

it('oneOf', function() {
Expand Down
8 changes: 8 additions & 0 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,10 @@ describe('should', function() {
err(function() {
(1.5).should.be.closeTo(1.0, true, 'blah');
}, "blah: the arguments to closeTo or approximately must be numbers");

err(function() {
(1.5).should.be.closeTo(1.0, undefined, 'blah');
}, "blah: the arguments to closeTo or approximately must be numbers, and a delta is required");
});

it('approximately', function(){
Expand All @@ -2816,6 +2820,10 @@ describe('should', function() {
err(function() {
(1.5).should.be.approximately(1.0, true);
}, "the arguments to closeTo or approximately must be numbers");

err(function() {
(1.5).should.be.approximately(1.0);
}, "the arguments to closeTo or approximately must be numbers, and a delta is required");
});

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

0 comments on commit 6441f3d

Please sign in to comment.