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

Check call count type #2410

Merged
merged 5 commits into from Jan 20, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/sinon/assert.js
Expand Up @@ -159,10 +159,16 @@ function createAssertObject() {
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");
Expand Down
3 changes: 2 additions & 1 deletion lib/sinon/proxy-call.js
Expand Up @@ -220,7 +220,8 @@ var callProto = {
}
}
if (this.stack) {
// Omit the error message and the two top stack frames in sinon itself:
// If we have a stack, add the first frame that's in end-user code
// Skip the first two frames because they will refer to Sinon code
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this through another round of editing, hopefully this is still clear

callStr += (this.stack.split("\n")[3] || "unknown").replace(
/^\s*(?:at\s+|@)?/,
" at "
Expand Down