Skip to content

Commit

Permalink
add calledOnceWith
Browse files Browse the repository at this point in the history
  • Loading branch information
krzkaczor authored and mroderick committed Feb 10, 2018
1 parent beea2f6 commit 5459212
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/sinon/spy.js
Expand Up @@ -423,6 +423,7 @@ spyApi.reset = deprecated.wrap(spyApi.resetHistory, deprecated.defaultMsg("reset
delegateToCalls("calledOn", true);
delegateToCalls("alwaysCalledOn", false, "calledOn");
delegateToCalls("calledWith", true);
delegateToCalls("calledOnceWith", true, "calledWith", undefined, 1);
delegateToCalls("calledWithMatch", true);
delegateToCalls("alwaysCalledWith", false, "calledWith");
delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch");
Expand Down
32 changes: 32 additions & 0 deletions test/spy-test.js
Expand Up @@ -1181,6 +1181,38 @@ describe("spy", function () {
});
});

describe(".calledOnceWith", function () {
beforeEach(function () {
this.spy = createSpy.create();
});

it("returns true for not exact match", function () {
this.spy(1, 2, 3, 4);

assert.isTrue(this.spy.calledOnceWith(1, 2, 3));
});

it("returns false for matching calls but called more then once", function () {
this.spy(1, 2, 3, 4);
this.spy(1, 2, 3, 6);

assert.isFalse(this.spy.calledOnceWith(1, 2, 3));
});

it("return false for one mismatched call", function () {
this.spy(1, 2);

assert.isFalse(this.spy.calledOnceWith(1, 2, 3));
});

it("return false for one mismatched call with some other ", function () {
this.spy(1, 2, 3);
this.spy(1, 2);

assert.isFalse(this.spy.calledOnceWith(1, 2, 3));
});
});

describe(".calledOnceWithExactly", function () {
beforeEach(function () {
this.spy = createSpy.create();
Expand Down

0 comments on commit 5459212

Please sign in to comment.