From 452981c6032afde45281f79bbb1d55c92db3674a Mon Sep 17 00:00:00 2001 From: Raul Matei Date: Tue, 6 Jun 2017 22:12:01 +0300 Subject: [PATCH] Fix 1445: make stubbing of static function properties possible --- lib/sinon/stub.js | 2 +- test/stub-test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/sinon/stub.js b/lib/sinon/stub.js index 60a4ac2ba..ce7aa5213 100644 --- a/lib/sinon/stub.js +++ b/lib/sinon/stub.js @@ -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") diff --git a/test/stub-test.js b/test/stub-test.js index 6af9b61bc..cfc269d92 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -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"); + }); }); });