diff --git a/lib/sinon.js b/lib/sinon.js index a0b171d05..e05fc7a1c 100644 --- a/lib/sinon.js +++ b/lib/sinon.js @@ -24,11 +24,8 @@ var apiMethods = { setFormatter: format.setFormatter, // fake timers - useFakeTimers: fakeTimers.useFakeTimers, - clock: fakeTimers.clock, timers: fakeTimers.timers, - // fake XHR xhr: nise.fakeXhr.xhr, FakeXMLHttpRequest: nise.fakeXhr.FakeXMLHttpRequest, diff --git a/lib/sinon/sandbox.js b/lib/sinon/sandbox.js index 9d63c084d..a33f95b13 100644 --- a/lib/sinon/sandbox.js +++ b/lib/sinon/sandbox.js @@ -17,6 +17,7 @@ var fakeXhr = require("nise").fakeXhr; var usePromiseLibrary = require("./util/core/use-promise-library"); // cache original versions, to prevent issues when they are stubbed in user space +var reverse = Array.prototype.reverse; var push = Array.prototype.push; var filter = Array.prototype.filter; var forEach = Array.prototype.filter; @@ -132,6 +133,7 @@ function Sandbox() { throw new Error("sandbox.restore() does not take any parameters. Perhaps you meant stub.restore()"); } + reverse.call(collection); applyOnEach(collection, "restore"); collection = []; diff --git a/test/issues/issues-test.js b/test/issues/issues-test.js index 0c3d84433..613efcec1 100644 --- a/test/issues/issues-test.js +++ b/test/issues/issues-test.js @@ -466,4 +466,17 @@ describe("issues", function () { // TypeError: Attempted to wrap someMethod which is already wrapped }); }); + + describe("#1801 - sinon.restore spied fakeTimers", function () { + it("should restore spied fake timers", function () { + var originalSetTimeout = setTimeout; + + sinon.useFakeTimers(); + sinon.spy(global, "setTimeout"); + + sinon.restore(); + + assert.same(originalSetTimeout, global.setTimeout, "fakeTimers restored"); + }); + }); }); diff --git a/test/sandbox-test.js b/test/sandbox-test.js index cd07744a1..fef2ca4b2 100644 --- a/test/sandbox-test.js +++ b/test/sandbox-test.js @@ -933,6 +933,17 @@ describe("Sandbox", function () { assert.same(setTimeout, originalSetTimeout, "fakeTimers restored"); }); + + it("restores spied fake timers when then sanddox is restored", function () { + var originalSetTimeout = setTimeout; + + this.sandbox.useFakeTimers(); + this.sandbox.spy(global, "setTimeout"); + + this.sandbox.restore(); + + assert.same(originalSetTimeout, global.setTimeout, "fakeTimers restored"); + }); }); describe(".usingPromise", function () {