Skip to content

Latest commit

 

History

History
76 lines (64 loc) · 11.3 KB

jest.md

File metadata and controls

76 lines (64 loc) · 11.3 KB

@code-pushup/eslint-config/jest config

Config for projects using Jest for testing.

🏗️ Setup

  1. If you haven't already, make sure to install @code-pushup/eslint-config and its required peer dependencies.

  2. Since this plugin requires additional peer dependencies, you have to install them as well:

    npm install -D eslint-plugin-jest
  3. Add to extends in your .eslintrc file:

    {
      "extends": ["@code-pushup/eslint-config/jest"],
      // customize rules if needed:
      "rules": {
        // e.g. to customize `test` or `it` usage (default is `it` in `describe` and `test` at top-level):
        "jest/consistent-test-it": ["warn", { "fn": "test", "withinDescribe": "test" }]
      }
    }

📏 Rules (37)

🔧 Automatically fixable by the --fix CLI option.
💡 Manually fixable by editor suggestions.

🚨 Errors (8)

Plugin Rule Options Autofix
jest no-identical-title
Disallow identical titles
jest no-interpolation-in-snapshots
Disallow string interpolation inside snapshots
jest no-jasmine-globals
Disallow Jasmine globals
🔧
jest no-test-prefixes
Require using .only and .skip over f and x
🔧
jest valid-describe-callback
Enforce valid describe() callback
jest valid-expect
Enforce valid expect() usage
🔧
jest valid-expect-in-promise
Require promises that have expectations in their chain to be valid
jest valid-title
Enforce valid titles
🔧

⚠️ Warnings (29)

Plugin Rule Options Autofix
jest consistent-test-it
Enforce test and it usage conventions
🔧
jest expect-expect
Enforce assertion to be made in a test body
jest max-nested-describe
Enforces a maximum depth to nested describe calls
max: 2
{
"max": 2
}
jest no-alias-methods
Disallow alias methods
🔧
jest no-commented-out-tests
Disallow commented out tests
jest no-conditional-expect
Disallow calling expect conditionally
jest no-deprecated-functions
Disallow use of deprecated functions
🔧
jest no-disabled-tests
Disallow disabled tests
jest no-done-callback
Disallow using a callback in asynchronous tests and hooks
💡
jest no-duplicate-hooks
Disallow duplicate setup and teardown hooks
jest no-export
Disallow using exports in files containing tests
jest no-focused-tests
Disallow focused tests
💡
jest no-mocks-import
Disallow manually importing from __mocks__
jest no-standalone-expect
Disallow using expect outside of it or test blocks
jest no-test-return-statement
Disallow explicitly returning from tests
jest prefer-comparison-matcher
Suggest using the built-in comparison matchers
🔧
jest prefer-each
Prefer using .each rather than manual loops
jest prefer-equality-matcher
Suggest using the built-in equality matchers
💡
jest prefer-expect-resolves
Prefer await expect(...).resolves over expect(await ...) syntax
🔧
jest prefer-hooks-on-top
Suggest having hooks before any test cases
jest prefer-mock-promise-shorthand
Prefer mock resolved/rejected shorthands for promises
🔧
jest prefer-spy-on
Suggest using jest.spyOn()
🔧
jest prefer-to-be
Suggest using toBe() for primitive literals
🔧
jest prefer-to-contain
Suggest using toContain()
🔧
jest prefer-to-have-length
Suggest using toHaveLength()
🔧
jest prefer-todo
Suggest using test.todo
🔧
jest require-hook
Require setup and teardown code to be within a hook
jest require-to-throw-message
Require a message for toThrow()
jest require-top-level-describe
Require test cases and hooks to be inside a describe block