Skip to content

Commit

Permalink
Fix 1445: make stubbing of static function properties possible
Browse files Browse the repository at this point in the history
  • Loading branch information
raulmatei committed Jun 6, 2017
1 parent 25f3eeb commit 452981c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sinon/stub.js
Expand Up @@ -18,7 +18,7 @@ function stub(object, property, descriptor) {
var isStubbingEntireObject = typeof property === "undefined" && typeof object === "object";
var isCreatingNewStub = !object && typeof property === "undefined";
var isStubbingDescriptor = object && property && Boolean(descriptor);
var isStubbingNonFuncProperty = typeof object === "object"
var isStubbingNonFuncProperty = (typeof object === "object" || typeof object === "function")
&& typeof property !== "undefined"
&& (typeof actualDescriptor === "undefined"
|| typeof actualDescriptor.value !== "function")
Expand Down
18 changes: 18 additions & 0 deletions test/stub-test.js
Expand Up @@ -2654,5 +2654,23 @@ describe("stub", function () {

assert.equals(getPropertyDescriptor(obj, "nonExisting"), undefined);
});

it("allows stubbing function static properties", function () {
var myFunc = function () {};
myFunc.prop = "rawString";

createStub(myFunc, "prop").value("newString");
assert.equals(myFunc.prop, "newString");
});

it("allows restoring function static properties", function () {
var myFunc = function () {};
myFunc.prop = "rawString";

var stub = createStub(myFunc, "prop").value("newString");
stub.restore();

assert.equals(myFunc.prop, "rawString");
});
});
});

0 comments on commit 452981c

Please sign in to comment.