diff --git a/lib/sinon/assert.js b/lib/sinon/assert.js index d2eb83335..da835b361 100644 --- a/lib/sinon/assert.js +++ b/lib/sinon/assert.js @@ -142,8 +142,14 @@ assert = { callCount: function assertCallCount(method, count) { verifyIsStub(method); - if (method.callCount !== count) { - var msg = "expected %n to be called " + timesInWords(count) + " but was called %c%C"; + var msg; + if (typeof count !== "number") { + msg = + `expected ${format(count)} to be a number ` + + `but was of type ${typeof count}`; + failAssertion(this, msg); + } else if (method.callCount !== count) { + msg = "expected %n to be called " + timesInWords(count) + " but was called %c%C"; failAssertion(this, method.printf(msg)); } else { assert.pass("callCount"); diff --git a/test/assert-test.js b/test/assert-test.js index 596e090eb..e83b8c670 100644 --- a/test/assert-test.js +++ b/test/assert-test.js @@ -1427,6 +1427,18 @@ describe("assert", function() { ); }); + it("assert.callCount exception message with non-numeric argument", function () { + this.obj.doSomething(); + + assert.equals( + this.message("callCount", this.obj.doSomething, "3").replace( + / at.*/g, + "" + ), + "expected '3' to be a number but was of type string" + ); + }); + it("assert.calledOnce exception message", function() { this.obj.doSomething(); this.obj.doSomething();