Skip to content

Instantly share code, notes, and snippets.

@erwinmombay
Created August 22, 2016 23:10
Show Gist options
  • Select an option

  • Save erwinmombay/777f40eb04df69d173b35a4c89ec819f to your computer and use it in GitHub Desktop.

Select an option

Save erwinmombay/777f40eb04df69d173b35a4c89ec819f to your computer and use it in GitHub Desktop.
vsync
import {installTimerService} from '../../src/service/timer-impl';
import {resetServiceForTesting} from '../../src/service';
describe('RAF polyfill', () => {
let sandbox;
let clock;
let vsync;
let fakeWin;
beforeEach(() => {
sandbox = sinon.sandbox.create();
clock = sandbox.useFakeTimers();
fakeWin = {
setTimeout: (fn, t) => {
window.setTimeout(fn, t);
},
};
const viewer = {
isVisible: () => true,
onVisibilityChanged: unusedHandler => {},
};
installTimerService(fakeWin);
vsync = new Vsync(fakeWin, viewer);
});
afterEach(() => {
resetServiceForTesting(fakeWin, 'timer');
sandbox.restore();
});
it('should schedule frames using the polyfill', () => {
let calls = 0;
vsync.mutate(() => {
calls++;
});
clock.tick(15);
vsync.mutate(() => {
calls++;
});
expect(calls).to.equal(0);
clock.tick(1);
expect(calls).to.equal(2);
clock.tick(10);
vsync.mutate(() => {
calls++;
});
expect(calls).to.equal(2);
clock.tick(6);
expect(calls).to.equal(3);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment