Skip to content

Commit

Permalink
Merge pull request sinonjs#322 from arielweinberger/feature/fix-immed…
Browse files Browse the repository at this point in the history
…iate-fire-315

Convert timer delay to number if not already
  • Loading branch information
benjamingr authored May 16, 2020
2 parents 7f8322e + a0ac099 commit 2ebd23c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/fake-timers-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ function withGlobal(_global) {
return Number.isFinite(num);
}

if (typeof num !== "number") {
return false;
}

return isFinite(num);
}

Expand Down Expand Up @@ -274,6 +270,10 @@ function withGlobal(_global) {
timer.type = timer.immediate ? "Immediate" : "Timeout";

if (timer.hasOwnProperty("delay")) {
if (typeof timer.delay !== "number") {
timer.delay = parseInt(timer.delay, 10);
}

if (!isNumberFinite(timer.delay)) {
timer.delay = 0;
}
Expand Down
13 changes: 13 additions & 0 deletions test/fake-timers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4605,3 +4605,16 @@ describe("#276 - remove config.target", function() {
}, /config.target is no longer supported/);
});
});

describe("issue #315 - praseInt if delay is not a number", function() {
it("should successfully execute the timer", function() {
var clock = FakeTimers.install();
var stub1 = sinon.stub();

clock.setTimeout(stub1, "1");
clock.tick(1);
assert(stub1.calledOnce);

clock.uninstall();
});
});

0 comments on commit 2ebd23c

Please sign in to comment.