-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Describe the bug
Tests for stopTimer assume a race condition, which almost always works, but occasionally fail. The test currently uses requestAnimationFrame to try to put itself at the back of the event loop, but there may be a better way to do it.
This is the relevant code, in graphics.test.js:
describe('Stopping a timer', () => {
it('Can be stopped by identity', () => {
const g = new Graphics();
const timerFn = jasmine.createSpy();
g.setTimer(timerFn, 0);
g.stopTimer(timerFn);
return new Promise(resolve => {
requestAnimationFrame(() => {
expect(timerFn).not.toHaveBeenCalled();
resolve();
});
});
});
it('Can be stopped by name', () => {
const g = new Graphics();
const spy = jasmine.createSpy();
g.setTimer(spy, 0);
return new Promise(resolve => {
requestAnimationFrame(() => {
expect(spy).toHaveBeenCalled();
// all jasmine spies are named 'wrap'
g.stopTimer('wrap');
requestAnimationFrame(() => {
expect(spy).toHaveBeenCalledTimes(1);
resolve();
});
});
});
});
it('stopAllTimers stops all timers', () => {
const g = new Graphics();
const timerOne = jasmine.createSpy();
const timerTwo = jasmine.createSpy();
g.setTimer(timerOne, 0, {}, 'one');
g.setTimer(timerTwo, 0, {}, 'two');
g.stopAllTimers();
return new Promise((resolve, reject) => {
requestAnimationFrame(() => {
expect(timerOne).not.toHaveBeenCalled();
expect(timerTwo).not.toHaveBeenCalled();
resolve();
});
});
});
});Metadata
Metadata
Assignees
Labels
No labels