Skip to content

Commit

Permalink
fix: runToLast should respect current time
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 17, 2018
1 parent 1278eaa commit 4983ee8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lolex-src.js
Expand Up @@ -720,7 +720,7 @@ function withGlobal(_global) {
return clock.now;
}

return clock.tick(timer.callAt);
return clock.tick(timer.callAt - clock.now);
};

clock.reset = function reset() {
Expand Down
20 changes: 20 additions & 0 deletions test/lolex-test.js
Expand Up @@ -1222,6 +1222,26 @@ describe("lolex", function () {
assert.isTrue(spy.called);
});

it("should support clocks with start time", function () {
var startingPoint = new Date("2018-01-01").getTime();
this.clock = lolex.createClock(startingPoint);
var runOrder = [];
var that = this;

this.clock.setTimeout(function cb() {
runOrder.push("mock1");
that.clock.setTimeout(cb, 49);
}, 50);

this.clock.setTimeout(function cb() {
runOrder.push("mock2");
}, 100);

this.clock.runToLast();

assert.equals(runOrder, ["mock1", "mock1", "mock2"]);
});

});

describe("clearTimeout", function () {
Expand Down

0 comments on commit 4983ee8

Please sign in to comment.