Skip to content

Commit

Permalink
Merge 8734800 into 1b05749
Browse files Browse the repository at this point in the history
  • Loading branch information
mantoni committed Jun 30, 2018
2 parents 1b05749 + 8734800 commit 8ccf116
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 37 deletions.
5 changes: 1 addition & 4 deletions lib/referee-sinon.js
Expand Up @@ -101,10 +101,7 @@ function verifyFakes() {
isNot = (method || "fake") + " is not ";

if (!method) { this.fail(isNot + "a spy"); }
if (typeof method !== "function") {
this.fail(isNot + "a function");
}
if (typeof method.getCall !== "function") {
if (typeof method.calledWith !== "function") {
this.fail(isNot + "stubbed");
}
}
Expand Down
83 changes: 50 additions & 33 deletions lib/referee-sinon.test.js
Expand Up @@ -19,20 +19,6 @@ referee.format = function () {
return formatter.ascii.apply(formatter, arguments);
};

function requiresFunction(assertion) {
var args = [32, "dummy argument"].concat([].slice.call(arguments, 1));

return function () {
assert.exception(function () {
assert[assertion].apply(assert, args);
}, {message: "32 is not a function"});

assert.exception(function () {
refute[assertion].apply(assert, args);
}, {message: "32 is not a function"});
};
}

function requiresSpy(assertion) {
var args = [function () {}, "dummy argument"].concat([].slice.call(arguments, 1));

Expand Down Expand Up @@ -109,7 +95,6 @@ describe("referee-sinon", function () {
});

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

it("passes when spy is explicitly passed null", function () {
Expand Down Expand Up @@ -142,10 +127,16 @@ describe("referee-sinon", function () {
assert.calledWith(spy, "foo");
assert.calledWithExactly(Array.prototype.slice, 1);
});

it("works with spy calls", function () {
var spy = sinon.spy();
spy(null, "Hey!");

assert.calledWith(spy.firstCall, null, "Hey!");
});
});

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

it("passes when spy is explicitly passed null", function () {
Expand All @@ -169,10 +160,16 @@ describe("referee-sinon", function () {
assert.match(e.message, message);
}
});

it("works with spy calls", function () {
var spy = sinon.spy();
spy(null, "Hey!");

assert.calledWithExactly(spy.firstCall, null, "Hey!");
});
});

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

it("passes when spy is passed matching object", function () {
Expand All @@ -199,10 +196,19 @@ describe("referee-sinon", function () {
assert.match(e.message, message);
}
});

it("works with spy calls", function () {
var spy = sinon.spy();
spy({
check: 123,
color: "#fff"
});

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

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

it("passes when spy is always passed matching object", function () {
Expand Down Expand Up @@ -241,7 +247,6 @@ describe("referee-sinon", function () {
});

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

it("passes when called once", function () {
Expand All @@ -264,7 +269,6 @@ describe("referee-sinon", function () {
});

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

it("passes when called twice", function () {
Expand Down Expand Up @@ -292,7 +296,6 @@ describe("referee-sinon", function () {
});

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

it("passes when called thrice", function () {
Expand Down Expand Up @@ -323,7 +326,6 @@ describe("referee-sinon", function () {
});

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

it("passes as callCount changes", function () {
Expand All @@ -347,7 +349,6 @@ describe("referee-sinon", function () {
});

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

it("passes when called once", function () {
Expand All @@ -371,7 +372,6 @@ describe("referee-sinon", function () {
});

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

it("passes when called with new", function () {
Expand All @@ -395,10 +395,18 @@ describe("referee-sinon", function () {
assert.equals(e.message, message);
}
});

it("works with spy calls", function () {
var spy = sinon.spy();

// eslint-disable-next-line no-new, new-cap
new spy();

assert.calledWithNew(spy.firstCall);
});
});

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

it("passes when always called with new", function () {
Expand Down Expand Up @@ -430,7 +438,6 @@ describe("referee-sinon", function () {
});

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

it("passes when called in order", function () {
Expand Down Expand Up @@ -466,7 +473,6 @@ describe("referee-sinon", function () {
});

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

it("passes when called on object", function () {
Expand All @@ -492,10 +498,17 @@ describe("referee-sinon", function () {
assert.equals(e.message, message);
}
});

it("works with spy calls", function () {
var spy = sinon.spy();
var object = { id: 42 };
spy.call(object);

assert.calledOn(spy.firstCall, object);
});
});

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

it("passes when called on object", function () {
Expand Down Expand Up @@ -524,7 +537,6 @@ describe("referee-sinon", function () {
});

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

it("passes when always called with same value", function () {
Expand Down Expand Up @@ -552,7 +564,6 @@ describe("referee-sinon", function () {
});

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

it("fails when spy is explicitly passed null", function () {
Expand All @@ -579,7 +590,6 @@ describe("referee-sinon", function () {
});

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

it("passes when spy threw", function () {
Expand All @@ -603,10 +613,18 @@ describe("referee-sinon", function () {
assert.match(e.message, message);
}
});

it("works with spy calls", function () {
var spy = sandbox.stub().throws();
try {
spy();
// eslint-disable-next-line no-empty
} catch (e) {}
assert.threw(spy.firstCall);
});
});

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

it("passes when spy always threw", function () {
Expand All @@ -633,7 +651,6 @@ describe("referee-sinon", function () {
});

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


Expand Down

0 comments on commit 8ccf116

Please sign in to comment.