Add clearTimeout to Timer and MockTimer

This commit is contained in:
Christopher Willis-Ford 2019-02-11 12:14:44 -08:00
parent 46a1ae83a0
commit 5a17bb1451
5 changed files with 155 additions and 69 deletions
test/unit

View file

@ -11,6 +11,8 @@ test('spec', t => {
t.type(timer.time, 'function');
t.type(timer.start, 'function');
t.type(timer.timeElapsed, 'function');
t.type(timer.setTimeout, 'function');
t.type(timer.clearTimeout, 'function');
t.end();
});
@ -40,3 +42,15 @@ test('start / timeElapsed', t => {
t.end();
}, delay);
});
test('setTimeout / clearTimeout', t => new Promise((resolve, reject) => {
const timer = new Timer();
const cancelId = timer.setTimeout(() => {
reject(new Error('Canceled task ran'));
}, 1);
timer.setTimeout(() => {
resolve('Non-canceled task ran');
t.end();
}, 2);
timer.clearTimeout(cancelId);
}));