Angular 11 Unit test for chart.js: Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)

Published

I am writing tests using Jest for components which uses chart.js to create a line chart. My chart is working totally fine but I am not able to write tests as I am getting the below error:

console.error
Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package) 
    at module.exports (D:chartsnode_modulesjsdomlibjsdombrowsernot-implemented.js:9:17)

Does anyone know how to fix it?

Source: Angular Questions

Published
Categorized as angular, chart.js, jestjs, unit-testing Tagged , , ,

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq