-
-
Notifications
You must be signed in to change notification settings - Fork 391
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
Advice for testing uPlot in unit tests (Jest) #497
Comments
there's this: https://www.npmjs.com/package/canvas, but it has no Path2D support: Automattic/node-canvas#1116 your best bet will be to automate a headless browser. see: https://jestjs.io/docs/puppeteer and |
also check out #175 |
Thanks for the fast response ❤️ ! Appreciate pointing me in the right direction on this. I have some automated tests with Cypress so that is definitely an option. I will experiment with the canvas library to see if that can give me what i was looking for, thanks! |
For anyone who comes across this issue in the future, Jest Canvas Mock (https://www.npmjs.com/package/jest-canvas-mock) did the trick of getting this library to render without errors. Note that nothing will actually render in the canvas so you will most likely need to go the browser test route if you want to test the functionality of uPlot in your app. |
Hi @hmillison, thanks for pointing towards this package. I'm quite curious how you ended up using this? Did you combine it with cypress or check all draw calls with jest? |
Curious what the best practice for interacting with uPlot in my UI unit tests is because uPlot is using canvas under the hood it seems to fail to render in the Jest environment due to
Uncaught TypeError: Cannot read property ‘clearRect’ of undefined
.Is the recommendation to mock
uPlot
in this case or is there a different approach used by folks?Environment used for testing:
Node 14.15
Jest, React v16, React Testing Library
The text was updated successfully, but these errors were encountered: