Skip to content

Commit e3fb6e0

Browse files
committed
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
1 parent c1cec44 commit e3fb6e0

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

test/messages.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ describe("Messages", function () {
102102
});
103103

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

112118
expect(function () {
113119
spyA.should.have.been.calledBefore(spyB);
114-
}).to.throw("expected spyA to have been called before function spyB() {}");
120+
}).to.throw(calledRegex(spyA, "have been called before", spyB));
115121

116122
if (spyA.calledImmediatelyBefore) {
117123
expect(function () {
118124
spyA.should.have.been.calledImmediatelyBefore(spyB);
119-
}).to.throw("expected spyA to have been called immediately before function spyB() {}");
125+
}).to.throw(calledRegex(spyA, "have been called immediately before", spyB));
120126
}
121127

122128
expect(function () {
123129
spyB.should.have.been.calledAfter(spyA);
124-
}).to.throw("expected spyB to have been called after function spyA() {}");
130+
}).to.throw(calledRegex(spyB, "have been called after", spyA));
125131

126132
if (spyB.calledImmediatelyAfter) {
127133
expect(function () {
128134
spyB.should.have.been.calledImmediatelyAfter(spyA);
129-
}).to.throw("expected spyB to have been called immediately after function spyA() {}");
135+
}).to.throw(calledRegex(spyB, "have been called immediately after", spyA));
130136
}
131137
});
132138

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

143149
expect(function () {
144150
spyA.should.not.have.been.calledBefore(spyB);
145-
}).to.throw("expected spyA to not have been called before function spyB() {}");
151+
}).to.throw(calledRegex(spyA, "not have been called before", spyB));
146152

147153
if (spyA.calledImmediatelyBefore) {
148154
expect(function () {
149155
spyA.should.not.have.been.calledImmediatelyBefore(spyB);
150-
}).to.throw("expected spyA to not have been called immediately before function spyB() {}");
156+
}).to.throw(calledRegex(spyA, "not have been called immediately before", spyB));
151157
}
152158

153159
expect(function () {
154160
spyB.should.not.have.been.calledAfter(spyA);
155-
}).to.throw("expected spyB to not have been called after function spyA() {}");
161+
}).to.throw(calledRegex(spyB, "not have been called after", spyA));
156162

157163
if (spyB.calledImmediatelyAfter) {
158164
expect(function () {
159165
spyB.should.not.have.been.calledImmediatelyAfter(spyA);
160-
}).to.throw("expected spyB to not have been called immediately after function spyA() {}");
166+
}).to.throw(calledRegex(spyB, "not have been called immediately after", spyA));
161167
}
162168
});
163169
});

0 commit comments

Comments
 (0)