-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
No longer possible to run tests for components which import plotly without a browser #1675
Comments
Thanks for tracking down this bug. I'm curious, what kind of tests are you running in node? I'm surprised that anything plotly.js works in node w/o at least using
It doesn't need to. But, apparently instantiating |
I actually am using jsdom 😉 was half asleep yesterday when I came across this! I can set up a DOMParser as is with jsDom, so all is good really for me, but ya maybe what you suggested would be better, to use |
Temporary fix to run tests that import const importPlotly = () => {
if(window.isTesting)
return {Plot: null, Plotly: null} // or Plot: <div />
const Plotly = require('plotly.js/dist/plotly.min.js');
const Plot = require('react-plotly.js');
return { Plot, Plotly };
};
const { Plot, Plotly } = importPlotly(); |
Recently a change was made to svg_text_utils.js which instantiates a DOMParser at the top level of that module:
plotly.js/src/lib/svg_text_utils.js
Line 22 in ce970f1
This has broken a number of tests I have which do not use a browser (or jsdom etc..) because the DOMParser will be instantiated on import, giving the following:
For now I've applied a very quick fix:
Can this be updated to something like the above? If not, then does the DOMParser really need to be at the top level?
The text was updated successfully, but these errors were encountered: