Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window.requestAnimationFrame not defined and nodeType null #1644

Closed
kennetpostigo opened this issue Sep 8, 2016 · 7 comments
Closed

window.requestAnimationFrame not defined and nodeType null #1644

kennetpostigo opened this issue Sep 8, 2016 · 7 comments

Comments

@kennetpostigo
Copy link

Hey,

I'm helping test an animation library and my tests are failing because it says that requestAnimationFrame is not defined and nodeType not defined. The code works I've verified that in codepen. However I think its because jest isn't exposing requestAnimationFrame property on the window object. Just to make sure here in MDN docs it should be on the window object. I console log the window object in the test and a very very large object is logged out to my terminal. I'm new to Jest but heres what the test looks like so I may be doing something wrong:

import React from 'react';
import renderer from 'react-test-renderer';
import Anime from './../src/Anime.js';

// fails with ReferenceError: requestAnimationFrame is not defined
it('Anime single child Snapshot', () => {
  const tree = renderer.create(
    <Anime easing="easeOutElastic"
           loop={true}
           duration={1000}
           direction="alternate"
           loop={true}
           delay={(el, index) => index * 240}
           translateX='13rem'
           scale={[.75, .9]}>
           <p>1</p>
      </Anime>
  ).toJSON();
  expect(tree).toMatchSnapshot();
});

// fails with TypeError: Cannot read property 'nodeType' of null
it('Anime multi-child Snapshot', () => {
  const tree = renderer.create(
    <Anime easing="easeOutElastic"
           loop={true}
           duration={1000}
           direction="alternate"
           loop={true}
           delay={(el, index) => index * 240}
           translateX='13rem'
           scale={[.75, .9]}>
           <p>1</p>
           <p>2</p>
           <p>3</p>
      </Anime>
  ).toJSON();
  expect(tree).toMatchSnapshot();
});
@cpojer
Copy link
Member

cpojer commented Sep 8, 2016

jsdom doesn't ship with requestAnimationFrame. You'll need to put a polyfill into your setupFiles config like this one: https://gist.github.com/paulirish/1579671

@cpojer cpojer closed this as completed Sep 8, 2016
@kennetpostigo
Copy link
Author

@cpojer okay just fixed that, do you know why the Cannot read property 'nodeType' of null is occurring? It happens here:

Before:

   // mutiple children failed test complains about the children not having key prop
  {children.map((child, i) => (React.cloneElement(child, {ref: this.addRef})))}

After:

  // so I added key to the prop and then Cannot read property 'nodeType' of null is caused
  {children.map((child, i) => (React.cloneElement(child, {key: i, ref: this.addRef})))}

@cpojer
Copy link
Member

cpojer commented Sep 8, 2016

The test renderer currently doesn't support refs; this is a feature the React team is currently working on.

@kennetpostigo
Copy link
Author

Okay, any timetable you may know of?

@cpojer
Copy link
Member

cpojer commented Sep 8, 2016

I think probably like 15.4 but I'm not on the React team, so not sure. See facebook/react#7649

@kennetpostigo
Copy link
Author

@cpojer thank you!

RusinovAnton added a commit to RusinovAnton/react-select3 that referenced this issue Nov 12, 2017
React 16 depends on RAF and jsdoc doesn't provide it out of box.
shim: https://gist.github.com/paulirish/1579671
refs: jestjs/jest#1644
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants