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

Bring calledWith messages more in line with Sinon's output #152

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Account for argument formatting in newer Sinon versions
This is a bit of a regression imo on Sinon's part, but I don't see an
easy way to adjust for it
cincodenada committed Nov 2, 2021
commit e3fb6e02e4d3710f1612660f28b59d7849101754
22 changes: 14 additions & 8 deletions test/messages.js
Original file line number Diff line number Diff line change
@@ -102,6 +102,12 @@ describe("Messages", function () {
});

describe("about call order", function () {
function calledRegex(func, criteria, otherFunc) {
return new RegExp(
"expected " + func.displayName + " to " + criteria +
" (function " + otherFunc.displayName + "\\(\\) \\{\\}|\\[Function\\])"
);
}
it("should be correct for the base cases", function () {
var spyA = sinon.spy();
var spyB = sinon.spy();
@@ -111,22 +117,22 @@ describe("Messages", function () {

expect(function () {
spyA.should.have.been.calledBefore(spyB);
}).to.throw("expected spyA to have been called before function spyB() {}");
}).to.throw(calledRegex(spyA, "have been called before", spyB));

if (spyA.calledImmediatelyBefore) {
expect(function () {
spyA.should.have.been.calledImmediatelyBefore(spyB);
}).to.throw("expected spyA to have been called immediately before function spyB() {}");
}).to.throw(calledRegex(spyA, "have been called immediately before", spyB));
}

expect(function () {
spyB.should.have.been.calledAfter(spyA);
}).to.throw("expected spyB to have been called after function spyA() {}");
}).to.throw(calledRegex(spyB, "have been called after", spyA));

if (spyB.calledImmediatelyAfter) {
expect(function () {
spyB.should.have.been.calledImmediatelyAfter(spyA);
}).to.throw("expected spyB to have been called immediately after function spyA() {}");
}).to.throw(calledRegex(spyB, "have been called immediately after", spyA));
}
});

@@ -142,22 +148,22 @@ describe("Messages", function () {

expect(function () {
spyA.should.not.have.been.calledBefore(spyB);
}).to.throw("expected spyA to not have been called before function spyB() {}");
}).to.throw(calledRegex(spyA, "not have been called before", spyB));

if (spyA.calledImmediatelyBefore) {
expect(function () {
spyA.should.not.have.been.calledImmediatelyBefore(spyB);
}).to.throw("expected spyA to not have been called immediately before function spyB() {}");
}).to.throw(calledRegex(spyA, "not have been called immediately before", spyB));
}

expect(function () {
spyB.should.not.have.been.calledAfter(spyA);
}).to.throw("expected spyB to not have been called after function spyA() {}");
}).to.throw(calledRegex(spyB, "not have been called after", spyA));

if (spyB.calledImmediatelyAfter) {
expect(function () {
spyB.should.not.have.been.calledImmediatelyAfter(spyA);
}).to.throw("expected spyB to not have been called immediately after function spyA() {}");
}).to.throw(calledRegex(spyB, "not have been called immediately after", spyA));
}
});
});