diff --git a/lib/sinon/fake.js b/lib/sinon/fake.js index 5d96b400b..eb3ab64a7 100644 --- a/lib/sinon/fake.js +++ b/lib/sinon/fake.js @@ -6,12 +6,39 @@ function getError(value) { return value instanceof Error ? value : new Error(value); } +function cleanProxy(f) { + var undesirableProperties = [ + "instantiateFake", + "callArg", + "callArgOn", + "callArgOnWith", + "callArgWith", + "invokeCallback", + "throwArg", + "withArgs", + "yield", + "yieldOn", + "yieldTo", + "yieldToOn" + ]; + + undesirableProperties.forEach(function (key) { + delete f[key]; + }); + + return f; +} + +function wrapFunc(f) { + return cleanProxy(spy(f)); +} + function fake(f) { if (typeof func !== "undefined" && typeof func !== "function") { throw new TypeError("Expected func argument to be a Function"); } - return spy(f); + return wrapFunc(f); } fake.returns = function returns(value) { @@ -19,7 +46,7 @@ fake.returns = function returns(value) { return value; } - return spy(f); + return wrapFunc(f); }; fake.throws = function throws(value) { @@ -27,7 +54,7 @@ fake.throws = function throws(value) { throw getError(value); } - return spy(f); + return wrapFunc(f); }; fake.resolves = function resolves(value) { @@ -35,7 +62,7 @@ fake.resolves = function resolves(value) { return Promise.resolve(value); } - return spy(f); + return wrapFunc(f); }; fake.rejects = function rejects(value) { @@ -43,7 +70,7 @@ fake.rejects = function rejects(value) { return Promise.reject(getError(value)); } - return spy(f); + return wrapFunc(f); }; module.exports = fake;