Skip to content

Commit

Permalink
fixed issue chaijs#923 custom message not always respected
Browse files Browse the repository at this point in the history
  • Loading branch information
artsoroka committed Feb 15, 2017
1 parent a7e1200 commit 73dfd9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ module.exports = function (chai, _) {
if (msg) flag(this, 'message', msg);
var obj = flag(this, 'object');

new Assertion(obj, msg).is.a('number');
this.is.a('number');
if (typeof expected !== 'number' || typeof delta !== 'number') {
throw new Error('the arguments to closeTo or approximately must be numbers');
}
Expand Down
13 changes: 13 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2328,6 +2328,19 @@ describe('expect', function () {
err(function() {
expect(1.5).to.be.closeTo(1.0, true);
}, "the arguments to closeTo or approximately must be numbers");

err(function() {
expect('blah', 'custom message').to.be.closeTo(2, 1);
},"custom message: expected 'blah' to be a number")

err(function() {
expect(10, 'custom message').to.be.closeTo(2, 1);
},"custom message: expected 10 to be close to 2 +/- 1")

err(function() {
expect(10, 'custom message').to.be.closeTo(2, 1, 'another message');
},"another message: expected 10 to be close to 2 +/- 1")

});

it('approximately', function(){
Expand Down

0 comments on commit 73dfd9b

Please sign in to comment.