Testing with Jest and Webpack aliases

前端 未结 7 1520
生来不讨喜
生来不讨喜 2020-12-14 14:48

I am looking to be able to use webpack aliases to resolve imports when using jest, and optimally, reference the webpack.aliases to avoid duplication.

Je

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 15:10

    This is a real insanity but when I try to map module in package.json like this:

    "jest": {
      "moduleNameMapper": {
        '@root/(.*)': '/../$1'
      }
    }
    

    It doesn't work.

    But when I do the same in jest.config.js it works:

    module.exports = {
       moduleNameMapper: {
         '@root/(.*)': '/../$1'
       }
    }
    

提交回复
热议问题