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

Sinon 9.1 #96

Merged
merged 5 commits into from
Oct 1, 2020
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
13 changes: 13 additions & 0 deletions lib/referee-sinon.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ referee.add("calledWithMatch", {
values: spyAndCalls
});

referee.add("calledOnceWithMatch", {
assert: function(spy) {
verifyFakes.call(this, spy);
return spy.calledOnceWithMatch.apply(spy, slice(arguments, 1));
},
assertMessage:
"Expected ${spyObj} to be called once with matching arguments ${expected}${actual}",
refuteMessage:
"Expected ${spyObj} not to be called once with matching arguments ${expected}${actual}",
expectation: "toHaveBeenCalledOnceWithMatch",
values: spyAndCalls
});

referee.add("alwaysCalledWithMatch", {
assert: function(spy) {
verifyFakes.call(this, spy);
Expand Down
70 changes: 70 additions & 0 deletions lib/referee-sinon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,76 @@ describe("referee-sinon", function() {
});
});

describe("calledOnceWithMatch", function() {
it(
"fails when not called with spy",
requiresSpy("calledOnceWithMatch")
);

it("passes when spy is passed matching object", function() {
var spy = sinon.spy();
spy({
check: 123,
color: "#fff"
});

assert.calledOnceWithMatch(spy, { check: 123 });
});

it("fails when spy is passes non-matching object", function() {
var spy = sinon.spy();
spy({
check: 123,
color: "#fff"
});

refute.calledOnceWithMatch(spy, { check: 321 });
});

it("fails when spy was called more than once", function() {
var spy = sinon.spy();
spy({
check: 123,
color: "#fff"
});
spy({
check: 321,
color: "#eee"
});

refute.calledOnceWithMatch(spy, { check: 123 });
});

context(
"when called more than once with same arguments",
function() {
it("fails", function() {
var spy = sinon.spy();
spy("hello", "Hey");
spy("hello", "Hey");

refute.calledOnceWithMatch(spy, "hello", "Hey");
});
}
);

it("formats message nicely", function() {
var spy = sinon.spy();
spy(null, 1, 2);

try {
assert.calledOnceWithMatch(spy, null, 2, 2);
throw new Error("Exception expected");
} catch (e) {
var message =
"[assert.calledOnceWithMatch] Expected " +
"function spy() {} to be called once with matching arguments " +
"null, 2, 2\n spy(null, 1, 2)";
assert.match(e.message, message);
}
});
});

describe("alwaysCalledWithMatch", function() {
it(
"fails when not called with spy",
Expand Down
Loading