sinonjs / fake-timers

Fake setTimeout and friends (collectively known as "timers"). Useful in your JavaScript tests. Extracted from Sinon.JS
BSD 3-Clause "New" or "Revised" License
806 stars 107 forks source link

Support timeout.refresh in node environments #328

Closed rgroothuijsen closed 4 years ago

rgroothuijsen commented 4 years ago

Purpose

Fix issue #187 by adding an actual implementation to refresh().

Background

Previously, refresh() was added to the timer API as an alternative to manually resetting timeouts via clearTimeout() and setTimeout(). However, while the interface itself was added, it remained a no-op function. This is confusing, since the presence of this function creates the expectation that the timer has been refreshed when it actually hasn't.

Solution

refresh() now clears the existing timeout and generates a new one with the same function and delay parameters, but a new ID.

codecov[bot] commented 4 years ago

Codecov Report

Merging #328 into master will increase coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #328      +/-   ##
==========================================
+ Coverage   93.11%   93.12%   +0.01%     
==========================================
  Files           1        1              
  Lines         552      553       +1     
==========================================
+ Hits          514      515       +1     
  Misses         38       38              
Flag Coverage Δ
#unit 93.12% <100.00%> (+0.01%) :arrow_up:
Impacted Files Coverage Δ
src/fake-timers-src.js 93.12% <100.00%> (+0.01%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 89e9e9b...2bcf132. Read the comment docs.