From 8d6330cc04fcf0c214fe93bffb9caeedeea31a17 Mon Sep 17 00:00:00 2001 From: Nathan Landis Date: Wed, 17 Apr 2019 16:31:57 -0500 Subject: [PATCH 1/2] Add delta message to closeTo() error --- chai.js | 3 ++- lib/chai/core/assertions.js | 3 ++- test/assert.js | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/chai.js b/chai.js index 39429c51b..f91d5b8f9 100644 --- a/chai.js +++ b/chai.js @@ -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 ); diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index cabcf622f..26404f5a8 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -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 ); diff --git a/test/assert.js b/test/assert.js index f9b3b1587..fd22d99cd 100644 --- a/test/assert.js +++ b/test/assert.js @@ -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(){ @@ -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() { From 6bfd2fd131cb4e70e0dd81c3be5d7f8a677adc04 Mon Sep 17 00:00:00 2001 From: Nathan Landis Date: Wed, 17 Apr 2019 16:44:03 -0500 Subject: [PATCH 2/2] Include some missed some test files --- test/expect.js | 8 ++++++++ test/should.js | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/test/expect.js b/test/expect.js index 9b4f485b8..6c87a8e84 100644 --- a/test/expect.js +++ b/test/expect.js @@ -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(){ @@ -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() { diff --git a/test/should.js b/test/should.js index 9a2400dfb..b7e1d2728 100644 --- a/test/should.js +++ b/test/should.js @@ -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(){ @@ -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() {