diff --git a/lib/sinon/sandbox.js b/lib/sinon/sandbox.js index 38ea72820..8a9123b5e 100644 --- a/lib/sinon/sandbox.js +++ b/lib/sinon/sandbox.js @@ -71,6 +71,26 @@ function Sandbox() { return sandbox.mock.apply(null, arguments); }; + obj.createStubInstance = function() { + return sandbox.createStubInstance.apply(sandbox, arguments); + }; + + obj.fake = function() { + return sandbox.fake.apply(null, arguments); + }; + + obj.replace = function() { + return sandbox.replace.apply(null, arguments); + }; + + obj.replaceSetter = function() { + return sandbox.replaceSetter.apply(null, arguments); + }; + + obj.replaceGetter = function() { + return sandbox.replaceGetter.apply(null, arguments); + }; + if (sandbox.clock) { obj.clock = sandbox.clock; } diff --git a/lib/sinon/util/core/default-config.js b/lib/sinon/util/core/default-config.js index 44914c35d..d47ca9aae 100644 --- a/lib/sinon/util/core/default-config.js +++ b/lib/sinon/util/core/default-config.js @@ -2,7 +2,19 @@ module.exports = { injectInto: null, - properties: ["spy", "stub", "mock", "clock", "server", "requests"], + properties: [ + "spy", + "stub", + "mock", + "clock", + "server", + "requests", + "fake", + "replace", + "replaceSetter", + "replaceGetter", + "createStubInstance" + ], useFakeTimers: true, useFakeServer: true }; diff --git a/test/sandbox-test.js b/test/sandbox-test.js index 79ecdbc35..315e713f3 100644 --- a/test/sandbox-test.js +++ b/test/sandbox-test.js @@ -1551,12 +1551,42 @@ describe("Sandbox", function() { this.sandbox.restore(); }); - it("injects spy, stub, mock", function() { + it("injects spy, stub, mock, fake, replace, replaceSetter, createStubInstance", function() { this.sandbox.inject(this.obj); assert.isFunction(this.obj.spy); assert.isFunction(this.obj.stub); assert.isFunction(this.obj.mock); + assert.isFunction(this.obj.createStubInstance); + assert.isFunction(this.obj.fake); + assert.isFunction(this.obj.replace); + assert.isFunction(this.obj.replaceSetter); + assert.isFunction(this.obj.replaceGetter); + }); + + it("should inject callable functions", function() { + /* eslint-disable no-empty-function, accessor-pairs */ + this.sandbox.inject(this.obj); + + var myObj = { a: function() {} }; + function MyClass() {} + Object.defineProperty(myObj, "b", { + get: function() { + return 42; + }, + configurable: true + }); + Object.defineProperty(myObj, "c", { set: function() {}, configurable: true }); + + refute.exception( + function() { + this.obj.createStubInstance(MyClass); + var fake = this.obj.fake(); + this.obj.replace(myObj, "a", fake); + this.obj.replaceGetter(myObj, "b", fake); + this.obj.replaceSetter(myObj, "c", fake); + }.bind(this) + ); }); it("does not define clock, server and requests objects", function() {