How to use ESLint with Jest

后端 未结 9 1668
滥情空心
滥情空心 2020-12-07 11:56

I\'m attempting to use the ESLint linter with the Jest testing framework.

Jest tests run with some globals like jest, which I\'ll need to tell the lin

相关标签:
9条回答
  • 2020-12-07 12:31

    To complete Zachary's answer, here is a workaround for the "extend in overrides" limitation of eslint config :

    overrides: [
      Object.assign(
        {
          files: [ '**/*.test.js' ],
          env: { jest: true },
          plugins: [ 'jest' ],
        },
        require('eslint-plugin-jest').configs.recommended
      )
    ]
    

    From https://github.com/eslint/eslint/issues/8813#issuecomment-320448724

    0 讨论(0)
  • 2020-12-07 12:31

    Pattern based configs are scheduled for 2.0.0 release of ESLint. For now, however, you will have to create two separate tasks (as mentioned in the comments). One for tests and one for the rest of the code and run both of them, while providing different .eslintrc files.

    P.S. There's a jest environment coming in the next release of ESLint, it will register all of the necessary globals.

    0 讨论(0)
  • 2020-12-07 12:38

    I solved the problem REF

    Run

    # For Yarn
    yarn add eslint-plugin-jest -D
    
    # For NPM
    npm i eslint-plugin-jest -D
    

    And then add in your .eslintrc file

    {
        "extends": ["airbnb","plugin:jest/recommended"],
    }
    
    0 讨论(0)
提交回复
热议问题