Advice for testing uPlot in unit tests (Jest)
See original GitHub issueCurious 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Jest Testing like a Pro - Tips and tricks
A (long) summary of best practices and tips to test your code with Jest. Tagged with unittesting, javascript, bestpractices, node.
Read more >Unit Testing With Jest in Javascript, Part II — React - Medium
When you want to test some of your React components using Jest unit testing, there are a few extra steps that should be...
Read more >How to test with jest and vue-test-utils simulate upload file
So write the test according to the actual (client) expectations. And than write the code which passes all expectations.
Read more >Successfully Throwing Async Errors with the Jest Testing Library
While automated tests like unit and integration tests are ... the upload, there were a lot of potential error scenarios to test for, ......
Read more >NetSuite Applications Suite - SuiteCloud Unit Testing with Jest
NetSuite Connector Third-Party Logistics (3PL) Sync Tests ... You can use SuiteCloud Unit Testing with Jest with SuiteCloud CLI for Node.js and your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?