plotly / react-plotly.js

A plotly.js React component from Plotly 📈
MIT License
1.02k stars 136 forks source link

testing with create-react-app #74

Open hanbyul-dl opened 6 years ago

hanbyul-dl commented 6 years ago

Hi! Thanks for all the good work.

I am trying to make the simple test that comes with create-react-app to work. (Which checks whole app renders without a crash)

I get an error like below.

    TypeError: Cannot read property 'document' of undefined

      at node_modules/plotly.js/dist/plotly.js:74:22
      at node_modules/plotly.js/dist/plotly.js:9620:2
      at Object.<anonymous>._$numerical_517.BADNUM (node_modules/plotly.js/dist/plotly.js:7:88)
      at Object.<anonymous> (node_modules/plotly.js/dist/plotly.js:7:327)
      at Object.<anonymous> (node_modules/react-plotly.js/react-plotly.js:11:15)
      at Object.<anonymous> (src/components/Graph/StyledGraph.js:2:20)
      at Object.<anonymous> (src/components/Graph/index.js:4:20)
      at Object.<anonymous> (src/container/GraphContainer.js:6:14)
      at Object.<anonymous> (src/App.js:7:23)
      at Object.<anonymous> (src/Main.js:14:12)
      at Object.<anonymous> (src/App.test.js:5:13)

I am using pretty much the default command that comes with create-react-app. (Test command node scripts/test.js --env=jsdom, react-app-preset) import Plotly from 'plotly.js/dist/basic';

I am using Plotly like below.

import Plotly from 'plotly.js/dist/basic';
import createPlotlyComponent from 'react-plotly.js/factory';
const Plot = createPlotlyComponent(Plotly);
HansG89 commented 5 years ago

I have exactly the same error. Is there already a solution for this?

mithi commented 4 years ago

I encountered a similar undefined issue (but not exactly) went away when I included 'jest-canvas-mock'

I was using the react testing library (NOT enzyme)

here:

But I encountered a different issue which is

Error while plotting: RangeError: Maximum call stack size exceeded

https://github.com/plotly/react-plotly.js/issues/186