Skip to content

Commit

Permalink
Add countTimers method
Browse files Browse the repository at this point in the history
Closes #213
  • Loading branch information
thejohnfreeman committed Oct 7, 2018
1 parent d4c2c05 commit 3ff4935
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lolex-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ function withGlobal(_global) {
return timer.id;
}


/* eslint consistent-return: "off" */
function compareTimers(a, b) {
// Sort first by absolute timing
Expand Down Expand Up @@ -574,6 +573,10 @@ function withGlobal(_global) {
return clearTimer(clock, timerId, "Immediate");
};

clock.countTimers = function countTimers() {
return Object.keys(clock.timers).length;
};

clock.requestAnimationFrame = function requestAnimationFrame(func) {
var result = addTimer(clock, {
func: func,
Expand Down
16 changes: 16 additions & 0 deletions test/lolex-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,22 @@ describe("lolex", function () {

});

describe("countTimers", function () {

beforeEach(function () {
this.clock = lolex.createClock();
});

it("counts remaining timers", function () {
this.clock.setTimeout(NOOP, 100);
this.clock.setTimeout(NOOP, 200);
this.clock.setTimeout(NOOP, 300);
this.clock.tick(150);
assert.equals(this.clock.countTimers(), 2);
});

});

describe("tick", function () {

beforeEach(function () {
Expand Down

0 comments on commit 3ff4935

Please sign in to comment.