Add 'finish' to time-based helpers
This commit is contained in:
parent
9f83eaa7a2
commit
bba5b1e653
11
lib/utils.js
11
lib/utils.js
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue