Setting up SVGR with Jest
Published
I was getting some errors in my unit test output because I converted my SVGs to React components using SVGR. As such, I needed to re-configure Jest accordingly.
- Create the mock file
export default "svgr-div"; // This is the kebab case that jest is looking for
export const ReactComponent = "div";
// @see https://react-svgr.com/docs/jest/ for setup
- Configure jest in
package.json
{
"jest": {
"moduleNameMapper": {
"\\.svg": "<rootDir>/PATH_TO_FOLDER/svg.js"
}
}
}