react-plotly.js icon indicating copy to clipboard operation
react-plotly.js copied to clipboard

testing with create-react-app

Open hanbyul-dl opened this issue 6 years ago • 2 comments

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);

hanbyul-dl avatar Apr 24 '18 17:04 hanbyul-dl

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

HansG89 avatar Jan 23 '19 13:01 HansG89

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:

  • https://github.com/mithi/hexapod/commit/f55dc3d49393c76787f2148bd2f3521c6c79ff7d

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

mithi avatar Jun 24 '20 02:06 mithi