Search code examples
reactjsenzymeantvg2plot

React enzyme jest test cases are failing with antv g2plot


I'm using the React Enzyme Jest module to test my React app which contains the antv/g2plot module for charts. While I am using the module, the test case isn't running but after removing it, it's working perfectly fine. There is a problem with the model I think. Do you know any possible solution?

I'm trying to test the file which is using the antv/g2plot module for chart while testing. It's failing and giving a random error which is not relevant (the error variable not defined in my React app). If I try to run the test without this file it's running pretty well but with it it returns this error.

enter image description here


Solution

  • I'm the member of G2Plot dev-team. When you write unit test for chart with canvas, you should:

    1. mock the canvas API, see https://github.com/hustcc/jest-canvas-mock
    2. give the real document(include canvas) env, see https://github.com/hustcc/jest-electron

    G2Plot use jest-electron for unit test and debugger.