Skip to content

Commit

Permalink
add tests to verify asserts on spyCalls
Browse files Browse the repository at this point in the history
  • Loading branch information
Flarna authored and mroderick committed Feb 24, 2018
1 parent 6e7e71f commit 7380a03
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions test/assert-test.js
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 7380a03

Please sign in to comment.