diff --git a/test/assert-test.js b/test/assert-test.js index 658e9ed19..0e30f0c6e 100644 --- a/test/assert-test.js +++ b/test/assert-test.js @@ -567,6 +567,30 @@ describe("assert", function () { assert(sinonAssert.pass.calledOnce); assert(sinonAssert.pass.calledWith("calledOn")); }); + + it("works with spyCall", function () { + var spy = sinonSpy(); + var target = {}; + spy(); + spy.call(target); + + sinonAssert.calledOn(spy.lastCall, target); + assert(sinonAssert.pass.calledOn); + assert(sinonAssert.pass.calledWith("calledOn")); + }); + + it("fails when spyCall failed", function () { + var spy = sinonSpy(); + var target = {}; + spy(); + spy.call(target); + + assert.exception(function () { + sinonAssert.calledOn(spy.lastCall, 1); + }); + + assert(sinonAssert.fail.called); + }); }); describe(".calledWithNew", function () { @@ -626,6 +650,28 @@ describe("assert", function () { assert(sinonAssert.pass.calledOnce); assert(sinonAssert.pass.calledWith("calledWithNew")); }); + + it("works with spyCall", function () { + var spy = sinonSpy(); + spy(); + new spy(); // eslint-disable-line no-new, new-cap + + sinonAssert.calledWithNew(spy.lastCall); + assert(sinonAssert.pass.calledWithNew); + assert(sinonAssert.pass.calledWith("calledWithNew")); + }); + + it("fails when spyCall failed", function () { + var spy = sinonSpy(); + spy(); + new spy(); // eslint-disable-line no-new, new-cap + + assert.exception(function () { + sinonAssert.calledWithNew(spy.firstCall); + }); + + assert(sinonAssert.fail.called); + }); }); describe(".alwaysCalledWithNew", function () { @@ -795,6 +841,30 @@ describe("assert", function () { assert(sinonAssert.pass.calledOnce); assert(sinonAssert.pass.calledWith("calledWithExactly")); }); + + it("works with spyCall", function () { + var spy = sinonSpy(); + var object = {}; + spy(); + spy(object); + + sinonAssert.calledWithExactly(spy.lastCall, object); + assert(sinonAssert.pass.calledOnce); + assert(sinonAssert.pass.calledWith("calledWithExactly")); + }); + + it("fails when spyCall failed", function () { + var spy = sinonSpy(); + var object = {}; + spy(); + spy(object); + + assert.exception(function () { + sinonAssert.calledWithExactly(spy.lastCall, 1); + }); + + assert(sinonAssert.fail.called); + }); }); describe(".neverCalledWith", function () { @@ -880,6 +950,28 @@ describe("assert", function () { assert(sinonAssert.pass.calledOnce); assert(sinonAssert.pass.calledWith("threw")); }); + + it("works with spyCall", function () { + var stub = sinonStub().throws("Error"); + assert.exception(function () { + stub(); + }); + + sinonAssert.threw(stub.firstCall, "Error"); + assert(sinonAssert.pass.threw); + assert(sinonAssert.pass.calledWith("threw")); + }); + + it("fails when spyCall failed", function () { + var stub = sinonStub().returns("Error"); + stub(); + + assert.exception(function () { + sinonAssert.threw(stub.firstCall, "Error"); + }); + + assert(sinonAssert.fail.called); + }); }); describe(".callCount", function () {