Skip to content

Commit

Permalink
Merge pull request #328 from rgroothuijsen/FAKE-TIMERS-187
Browse files Browse the repository at this point in the history
Support timeout.refresh in node environments
  • Loading branch information
benjamingr authored Jun 6, 2020
2 parents 89e9e9b + 2bcf132 commit cb4c2f6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/fake-timers-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ function withGlobal(_global) {
return res;
},
refresh: function() {
return res;
clearTimeout(timer.id);
return setTimeout(timer.func, timer.delay);
}
};
return res;
Expand Down
27 changes: 27 additions & 0 deletions test/fake-timers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit cb4c2f6

Please sign in to comment.