diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index 89281afa6..5b5bb84ba 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -376,7 +376,7 @@ var spyApi = { formatter = spyApi.formatters[specifyer]; if (typeof formatter === "function") { - return formatter.call(null, spyInstance, args); + return String(formatter.call(null, spyInstance, args)); } else if (!isNaN(parseInt(specifyer, 10))) { return sinonFormat(args[specifyer - 1]); } diff --git a/test/assert-test.js b/test/assert-test.js index c881f6cff..658e9ed19 100644 --- a/test/assert-test.js +++ b/test/assert-test.js @@ -1649,4 +1649,42 @@ describe("assert", function () { " actual = { foo: 1 }"); }); }); + + if (typeof Symbol === "function") { + describe("with symbol method names", function () { + var obj = {}; + + function setupSymbol(symbol) { + obj[symbol] = function () {}; + sinonSpy(obj, symbol); + } + + function createExceptionMessage(method, arg) { + try { // eslint-disable-line no-restricted-syntax + sinonAssert[method](arg); + } catch (e) { + return e.message; + } + } + + it("should use the symbol's description in exception messages", function () { + var symbol = Symbol("Something Symbolic"); + setupSymbol(symbol); + + assert.equals(createExceptionMessage("called", obj[symbol]), + "expected Symbol(Something Symbolic) to have been " + + "called at least once but was never called"); + }); + + it("should indicate that an assertion failure with a symbol method name " + + "occured in exception messages, even if the symbol has no description", function () { + var symbol = Symbol(); + setupSymbol(symbol); + + assert.equals(createExceptionMessage("called", obj[symbol]), + "expected Symbol() to have been " + + "called at least once but was never called"); + }); + }); + } });