question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Advice for testing uPlot in unit tests (Jest)

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
hmillisoncommented, Apr 19, 2021

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.

0reactions
nielsuit227commented, May 25, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found