Skip to content

Commit

Permalink
Include time since window initialised in rAF implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 30, 2017
1 parent b3f85a2 commit 4968028
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
test('requestAnimationFrame test', done => {
expect.hasAssertions();

requestAnimationFrame(() => {
requestAnimationFrame(timestamp => {
expect(true).toBe(true);
expect(timestamp).toBeGreaterThan(0);

done();
});
Expand Down
7 changes: 6 additions & 1 deletion packages/jest-environment-jsdom/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class JSDOMEnvironment {
moduleMocker: ?ModuleMocker;

constructor(config: ProjectConfig): void {
const jsdomInitialized = process.hrtime();
// lazy require
this.document = JSDom.jsdom('<!DOCTYPE html>', {
url: config.testURL,
Expand All @@ -34,7 +35,11 @@ class JSDOMEnvironment {

if (!global.requestAnimationFrame) {
global.requestAnimationFrame = callback => {
global.setTimeout(callback, 0);
const hr = process.hrtime(jsdomInitialized);
const hrInNano = hr[0] * 1e9 + hr[1];
const hrInMicro = hrInNano / 1e6;

return global.setTimeout(callback, 0, hrInMicro);
};
}

Expand Down

0 comments on commit 4968028

Please sign in to comment.