diff --git a/src/fake-timers-src.js b/src/fake-timers-src.js index 59f1f7d6..c969a854 100644 --- a/src/fake-timers-src.js +++ b/src/fake-timers-src.js @@ -312,7 +312,8 @@ function withGlobal(_global) { return res; }, refresh: function() { - return res; + clearTimeout(timer.id); + return setTimeout(timer.func, timer.delay); } }; return res; diff --git a/test/fake-timers-test.js b/test/fake-timers-test.js index 02170308..b5820d55 100644 --- a/test/fake-timers-test.js +++ b/test/fake-timers-test.js @@ -4595,3 +4595,30 @@ describe("issue #315 - praseInt if delay is not a number", function() { clock.uninstall(); }); }); + +describe("#187 - Support timeout.refresh in node environments", function() { + it("calls the stub again after refreshing the timeout", function() { + var clock = FakeTimers.install(); + var stub = sinon.stub(); + + if (typeof setTimeout(NOOP, 0) === "object") { + var t = setTimeout(stub, 1000); + clock.tick(1000); + t.refresh(); + clock.tick(1000); + assert(stub.calledTwice); + } + clock.uninstall(); + }); + + it("assigns a new id to the refreshed timer", function() { + var clock = FakeTimers.install(); + var stub = sinon.stub(); + if (typeof setTimeout(NOOP, 0) === "object") { + var t = setTimeout(stub, 1000); + var t2 = t.refresh(); + refute.same(t.id, t2.id); + } + clock.uninstall(); + }); +});