添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
慷慨大方的镜子  ·  ml-mastery-zh-pt2/docs ...·  4 月前    · 
风流的消防车  ·  Exoplayer ...·  6 月前    · 
安静的生菜  ·  External http access ...·  7 月前    · 
重情义的小熊猫  ·  Perl LDAP - ldap.perl.org·  9 月前    · 

If you're using jest and you have installed custom name mappings in your config via the moduleNameMapper config and you're using the wonderful eslint-plugin-import you might get yelled at by eslint:

(I oftentimes create an alias for the helpers I use for testing)

Let's fix this!
yarn add eslint-import-resolver-jest -D
npm i eslint-import-resolver-jest -D

If you are using the package.json config option from jest everything should _just work_™.

If you are using a separate config file for jest using the --config option you have to point this plugin to it, too (in your .eslintrc):

"settings": {
  "import/resolver": {
    "jest": {
      "jestConfigFile": "./jest.conf.json"

That's it!

If you want to ensure that this resolver only applies to your test files, you can use ESLint's overrides configuration option:

"overrides": [
    "files": ["**/__tests__/**/*.js"],
    "settings": {
      "import/resolver": {
        "jest": {
          "jestConfigFile": "./jest.conf.json"

It will only resolve the modules in your test files that you specified via testRegex or testMatch in your jest config.

Contributing

Create issues in this repo or get active yourself:

yarn test # npm test works, too
License