diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index 75cc5d44d..97681c581 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -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"); diff --git a/test/spy-test.js b/test/spy-test.js index 059400364..44bba6df4 100644 --- a/test/spy-test.js +++ b/test/spy-test.js @@ -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();