Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1445: make stubbing of static function properties possible #1450

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sinon/stub.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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");
});
});
});