HesamSe
HesamSe

Reputation: 355

Testing components using jest that includes canvas

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.

Upvotes: 4

Views: 1345

Answers (0)

Related Questions