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

requestAnimationFrame not supported error when unit testing a d3 transition react component #12752

Closed
alphagamer7 opened this issue May 6, 2018 · 1 comment

Comments

@alphagamer7
Copy link

alphagamer7 commented May 6, 2018

I use d3 with transition in my react component similar to this example (http://bl.ocks.org/d3noob/7030f35b72de721622b8) where transition happens on button click.

The unit test

const graphData = data;

const transactionDetail = {
	displayFrom: "2018-05-01",
	displayTo: "2018-06-01"
};

const component = shallow(<TimelineGraph graphData={graphData} transactionDetail={transactionDetail} />);

describe("TimelineGraph", function() {
	test("should render svg", function() {
		expect(component.find("svg")).to.have.length(1);
	});
	test("should handle click anchor tag", () => {
		const handleClick = component.find("a").first();
		expect(handleClick.prop.length).to.equal(1);
	});
});

The error

  ● Test suite failed to run

    requestAnimationFrame is not supported in Node

       5 | window.addEventListener = () => {};
       6 | window.requestAnimationFrame = () => {
    >  7 | 	throw new Error("requestAnimationFrame is not supported in Node");
       8 | };
       9 | 
      10 | module.exports = react;
      
      at Object.<anonymous>.window.requestAnimationFrame (__mocks__/react.js:7:8)
      at Object.now (node_modules/d3-timer/build/d3-timer.js:21:23)
      at Selection.selection_transition [as transition] (node_modules/d3-transition/build/d3-transition.js:745:59)
      at TimelineGraph._this.renderYAxis (src/components/Graphs/TimelineGraph/index.js:74:35)
      at TimelineGraph.renderGraph (src/components/Graphs/TimelineGraph/index.js:249:622)
      at TimelineGraph.componentDidMount (src/components/Graphs/TimelineGraph/index.js:249:429)
      at node_modules/enzyme/build/ShallowWrapper.js:126:20
      at Object.batchedUpdates (node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:342:22)
      at new ShallowWrapper (node_modules/enzyme/build/ShallowWrapper.js:125:24)
      at shallow (node_modules/enzyme/build/shallow.js:19:10)
      at Object.<anonymous> (src/components/Graphs/TimelineGraph/TimelineGraph.test.js:16:37)

When I test the component, I get this requestAnimationFrame is not supported in Node exception from the issue #9102 thrown even when I try to use d3 timer(https://groups.google.com/forum/#!topic/d3-js/BioLtR9ixYE). Is there any way of overcoming this thrown exception other than by removing the thrown exception code mentioned in #9102 issue ?

Info:

react : 16.2.0
react-dom-16.2.0
enzyme -3.3.0
react-test-renderer-16.2.0
OS : Windows 10

@aweary
Copy link
Contributor

aweary commented May 6, 2018

Hey there! We use the issue tracker for bug reports and feature requests.

If you have a question, please check our community support resources:
https://facebook.github.io/react/community/support.html

@aweary aweary closed this as completed May 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants