Testing with Jest and Webpack aliases

前端 未结 7 1511
生来不讨喜
生来不讨喜 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 14:59

    None of the prescribed answers worked for me.

    Was able to solve with the following pattern:

    Jest version 25+

    moduleNameMapper: {
        '^Screens(.*)': '/src/screens/$1',
        '^Components(.*)': '/src/components/$1',
        '^Assets(.*)': '/src/assets/$1',
        '^Services/(.*)': '/src/services/$1',
      },
    

提交回复
热议问题