Craft By Zen

Writing

  • Setting up SVGR with Jest
    Posted

    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.

    1. 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
    
    1. Configure jest in package.json
    {
      "jest": {
        "moduleNameMapper": {
          "\\.svg": "<rootDir>/PATH_TO_FOLDER/svg.js"
        }
      }
    }
    
    Filed: 🚰 Stream
🔖 Tags