4

I'm trying to test zoomcharts component in my react app with Enzyme and jest. There is a reference error relevant to canvas. Here is my test case:

import Chart from './Shared/Chart';
import { shallow } from 'enzyme';

describe('test 1',()=>{
    it('Chart',()=>{
        let wrapper = shallow(<Chart/>);
    });
});

and here is my error when I run my test:

ReferenceError: CanvasGradient is not defined

  28 |             ]
  29 |         };
> 30 |         this.chart = new zc.NetChart({
     |                      ^
  31 |             container: this.container, 
  32 |             area: { height: 350 },
  33 |             data: { preloaded: data }

Is there any problem with testing components that includes canvas element? How can I mock this CanvasGradient thing? I've already tried jest-canvas-mock. Thanks.

brass monkey
  • 5,841
  • 10
  • 36
  • 61
HesamSe
  • 195
  • 1
  • 2
  • 11
  • I've made a similar post [here](https://stackoverflow.com/questions/64984083/charts-created-using-react-chartjs-2-throw-an-error-in-a-jest-environment). No solution yet. – RubbelDieKatz Nov 25 '20 at 12:08

0 Answers0