Created
August 22, 2016 23:10
-
-
Save erwinmombay/777f40eb04df69d173b35a4c89ec819f to your computer and use it in GitHub Desktop.
vsync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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