Search code examples
reactjsjestjsamchartsamcharts4

Jest with amCharts4 in reactjs


Test cases are failing for the components using amcharts4. I've tried using

"jest": {
"transformIgnorePatterns": [
  "[/\\\\]node_modules[/\\\\](?!(@amcharts)\\/).+\\.(js|jsx|ts|tsx)$"
],}

but this did not resolve the issue. The documentation of amCharts mentioned that it can be resolved using jest with puppeteer. Does anybody know any other workaround to this problem? Using jest with puppeteer is the only solution?


Solution

  • We need to add the below code in jest config and also if you are using mount/shallow for testing then move to ReactDOM.render() as jest does not support testing SVG and amCharts use SVG internally.

    "jest": {
     "transformIgnorePatterns": [
        "node_modules[/\\\\](?!@amcharts[/\\\\]amcharts4)"
     ]
    }