Skip to content

Commit

Permalink
Merge pull request #208 from SimenB/run-to-last-loop
Browse files Browse the repository at this point in the history
fix: runToLast should respect current time
  • Loading branch information
fatso83 committed Sep 18, 2018
2 parents f1f80da + a6c0308 commit cbaa8ba
Show file tree
Hide file tree
Showing 2 changed files with 16 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
15 changes: 15 additions & 0 deletions test/lolex-test.js
Expand Up @@ -1222,6 +1222,21 @@ describe("lolex", function () {
assert.isTrue(spy.called);
});

it("should support clocks with start time", function () {
this.clock = lolex.createClock(200);
var that = this;
var invocations = 0;

this.clock.setTimeout(function cb() {
invocations++;
that.clock.setTimeout(cb, 50);
}, 50);

this.clock.runToLast();

assert.equals(invocations, 1);
});

});

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

0 comments on commit cbaa8ba

Please sign in to comment.