5.4.0 • Published 6 days ago

eslint-plugin-jest-dom v5.4.0

Weekly downloads
194,513
License
MIT
Repository
github
Last release
6 days ago

Build Status Code Coverage version downloads MIT License All Contributors PRs Welcome Code of Conduct

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev eslint-plugin-jest-dom

This library has a required peerDependencies listing for ESLint.

Usage

!NOTE

eslint.config.js is supported, though most of the plugin documentation still currently uses .eslintrc syntax; compatible versions of configs are available prefixed with flat/ and may be subject to small breaking changes while ESLint v9 is being finalized.

Refer to the ESLint documentation on the new configuration file format for more.

Add jest-dom to the plugins section of your .eslintrc.js configuration file. You can omit the eslint-plugin- prefix:

module.exports = {
  plugins: ["jest-dom"],
  rules: {
    // your configuration
  },
};

Then configure the rules you want to use under the rules section.

module.exports = {
  rules: {
    "jest-dom/prefer-checked": "error",
    "jest-dom/prefer-enabled-disabled": "error",
    "jest-dom/prefer-required": "error",
    "jest-dom/prefer-to-have-attribute": "error",
  },
};

Recommended Configuration

This plugin exports a recommended configuration that enforces good jest-dom practices (you can find more info about enabled rules in Supported Rules section).

To enable this configuration with .eslintrc, use the extends property:

module.exports = {
  extends: "plugin:jest-dom/recommended",
  rules: {
    // your configuration
  },
};

To enable this configuration with eslint.config.js, use jestDom.configs['flat/recommended']:

module.exports = [
  {
    files: [
      /* glob matching your test files */
    ],
    ...require("eslint-plugin-jest-dom").configs["flat/recommended"],
  },
];

Supported Rules

💼 Configurations enabled in.\ ✅ Set in the recommended configuration.\ 🔧 Automatically fixable by the --fix CLI option.\ 💡 Manually fixable by editor suggestions.

Name                       Description💼🔧💡
prefer-checkedprefer toBeChecked over checking attributes🔧
prefer-emptyPrefer toBeEmpty over checking innerHTML🔧
prefer-enabled-disabledprefer toBeDisabled or toBeEnabled over checking attributes🔧
prefer-focusprefer toHaveFocus over checking document.activeElement🔧
prefer-in-documentPrefer .toBeInTheDocument() for asserting the existence of a DOM node🔧💡
prefer-requiredprefer toBeRequired over checking properties🔧
prefer-to-have-attributeprefer toHaveAttribute over checking getAttribute/hasAttribute🔧
prefer-to-have-classprefer toHaveClass over checking element className🔧
prefer-to-have-styleprefer toHaveStyle over checking element style🔧
prefer-to-have-text-contentPrefer toHaveTextContent over checking element.textContent🔧
prefer-to-have-valueprefer toHaveValue over checking element.value🔧

Issues

Looking to contribute? Look for the Good First Issue label.

🐛 Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior.

See Bugs

💡 Feature Requests

Please file an issue to suggest new features. Vote on feature requests by adding a 👍. This helps maintainers prioritize what to work on.

See Feature Requests

Contributors ✨

Thanks goes to these people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

@giveerr/rollpkg@corva/ui@redwoodjs/eslint-confignora-setup@grenadierjs/eslint-config@lednhatkhanh/eslint-config-next-appeslint-config-refined@martynastell/build-configs@martynastell/eslint-config@alfabank/eslint-config-siteeslint-config-martyncherryeslint-config-rbower@martyncherry/eslint-config-ts@element-design/eslint-config@infinitebrahmanuniverse/nolb-eslint-plugin-jeslint-config-sandbox@everything-registry/sub-chunk-1612eslint-config-wishket@indonesiafurs/style-guide@ventsislavnikolov/eslint-configmysql-ksdb@developer-kit/eslint-config@carv/eslint-config@anylint/eslint-config@aqzhyi/eslint@archer-oss/dev-scripts@apitree.cz/eslint-config@appnroll/eslint-config@aprets/config@dexaai/eslint-config@digitalinsurance/eslint-config-dig@changeset-test123/config@chipp972/eslint-config@corva/dc-platform-shared@cprussin/eslint-config@col0ring/eslint-config@consta/widgets-configs@cosmonic/eslint-config@colussi/eslint-config@commercetools-frontend/eslint-config-mc-app@comparto/eslint-config@drivekyte/eslint-config@cityelectricalfactors/ui-components@code-shaper/eslint-config@codeboxx/eslint-config@codeboxx/eslint-config-codeboxx@coolizz/eslint-config@croct/eslint-plugin@darekkay/eslint-config@danielsepulveda/eslint-config@fuel-ui/config@fuels/eslint-config@fuels/eslint-plugin@dataorb.co/eslint-config@dataspai/eslint-config@gaze-ui/eslint-config@voltiso/config.eslint@voltiso/eslint-config@voltiso/eslint-config-fast@ttoss/eslint-config@twipped/eslint-config@zettca/eslint-config-uikit-react@zextras/carbonio-ui-configs@berlysia/eslint-config@benbender/eslint-config@arinthros/common@arinthros/eslint-config@arquivei/eslint-config@arters/eslint-config@beuluis/eslint-config@auditorium-ai/eslint-config@benmvp/cli@brexhq/eslint-config-ui-config@brexhq/typescript-code-style@builderdao/config@babbel/eslint-config@budarin/spa-react-app-config@brummelte/eslint-config@byte-craft-react/eslint-config@byndyusoft/eslint-config@c1495616js/eslint-config@byintera/eslint-config@bamdadsabbagh/eslint-config@bedrockstreaming/eslint-config-jest@bayathy/eslint-config-jest@atir-naveed-geeksltd/eslint-config@gergerwuu/eslint-config@getracker/eslint-config@wesp-up/eslint-config-react@we-are-singular/eslint-configwetravel-eslint-config@veriff/eslint-config@alergeek-ventures/eslint-config@adeira/eslint-config@adhamu/zero@adchitects/eslint-config@americanexpress/lumberjack@xyzproject/react-linting-standards@troyblank/eslint-config-troyblank@trigen/eslint-config
5.3.0

7 days ago

5.4.0

6 days ago

5.1.1

1 month ago

5.2.0

1 month ago

5.1.0

8 months ago

5.0.2

9 months ago

5.0.1

11 months ago

5.0.0

11 months ago

4.0.3

1 year ago

4.0.2

2 years ago

3.9.3

2 years ago

3.9.4

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.9.2

3 years ago

3.9.1

3 years ago

3.9.0

3 years ago

3.8.1

3 years ago

3.8.0

3 years ago

3.7.0

3 years ago

3.6.5

3 years ago

3.6.4

3 years ago

3.6.3

3 years ago

3.6.2

3 years ago

3.6.1

3 years ago

3.6.0

3 years ago

3.5.0

3 years ago

3.4.2

3 years ago

3.4.1

3 years ago

3.4.0

3 years ago

3.3.0

3 years ago

3.2.4

4 years ago

3.2.3

4 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.7

4 years ago

3.1.6

4 years ago

3.1.5

4 years ago

3.1.4

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago