Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion error messages handle symbolic method names #1642

Merged
merged 1 commit into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sinon/spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
38 changes: 38 additions & 0 deletions test/assert-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
}
});