mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-05-17 00:41:24 -04:00
Add clearTimeout
to Timer and MockTimer
This commit is contained in:
parent
46a1ae83a0
commit
5a17bb1451
5 changed files with 155 additions and 69 deletions
test/unit
|
@ -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);
|
||||
}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue