Skip to content

Commit

Permalink
Fix #1781: Reject non-function values a f argument to fake
Browse files Browse the repository at this point in the history
  • Loading branch information
mroderick committed May 5, 2018
1 parent 5503f73 commit 3a66331
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/sinon/fake.js
Expand Up @@ -54,8 +54,8 @@ function wrapFunc(f) {
}

function fake(f) {
if (typeof func !== "undefined" && typeof func !== "function") {
throw new TypeError("Expected func argument to be a Function");
if (arguments.length > 0 && typeof f !== "function") {
throw new TypeError("Expected f argument to be a Function");
}

return wrapFunc(f);
Expand Down
12 changes: 11 additions & 1 deletion test/fake-test.js
Expand Up @@ -23,7 +23,7 @@ referee.add("isProxy", {

function verifyProxy(func, argument) {
it("should return a Sinon proxy", function () {
var actual = func(argument);
var actual = argument ? func(argument) : func();

assert.isProxy(actual);
});
Expand Down Expand Up @@ -51,6 +51,16 @@ describe("fake", function () {
verifyProxy(fake);
});

it("should reject non-Function argument", function () {
var nonFuncs = ["", 123, new Date(), {}, false, undefined, true, null];

nonFuncs.forEach(function (nf) {
assert.exception(function () {
fake(nf);
});
});
});

describe(".callback", function () {
it("it should be a reference for the callback in the last call", function () {
var f = fake();
Expand Down

0 comments on commit 3a66331

Please sign in to comment.