Add 'finish' to time-based helpers

This commit is contained in:
deadprogram 2015-09-01 11:30:55 -07:00
parent 9f83eaa7a2
commit bba5b1e653
2 changed files with 30 additions and 0 deletions

View File

@ -42,6 +42,17 @@ var Utils = module.exports = {
return every(0, action);
},
/**
* A wrapper around clearInterval
*
* @param {intervalID} action function to invoke constantly
* @example stop(blinking);
* @return {void}
*/
finish: function finish(intervalID) {
clearInterval(intervalID);
},
/**
* Sleeps the program for a period of time.
*

View File

@ -71,6 +71,25 @@ describe("Utils", function() {
});
});
describe("#finish", function() {
beforeEach(function() {
this.clock = sinon.useFakeTimers();
});
afterEach(function() {
this.clock.restore();
});
it("stops calling an interval function", function() {
var func = spy();
var interval = utils.every(10, func);
this.clock.tick(15);
utils.finish(interval);
this.clock.tick(15);
expect(func).to.be.calledOnce;
});
});
describe("#subclass", function() {
var BaseClass = function BaseClass(opts) {
this.greeting = opts.greeting;