Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

eslint-plugin-jest

Package Overview
Dependencies
Maintainers
9
Versions
326
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jest

ESLint rules for Jest

  • 28.9.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12M
increased by0.21%
Maintainers
9
Weekly downloads
Β 
Created

What is eslint-plugin-jest?

The eslint-plugin-jest package is an ESLint plugin that provides linting rules for Jest, a popular JavaScript testing framework. It helps maintain code quality and enforce best practices by analyzing test files for common issues and stylistic preferences.

What are eslint-plugin-jest's main functionalities?

Enforcing consistent test descriptions

This rule enforces a consistent test function name, either `test` or `it`, within the test files.

/* eslint jest/consistent-test-it: ["error", { fn: "test" }] */

// Incorrect
describe('myFeature', () => {
  it('does something', () => {
    // test implementation
  });
});

// Correct
describe('myFeature', () => {
  test('does something', () => {
    // test implementation
  });
});

Preventing disabled tests

This rule prevents the use of `xdescribe`, `xit`, or `test.skip`, which are used to disable tests, to ensure that all tests are run.

/* eslint jest/no-disabled-tests: "error" */

// Incorrect
xdescribe('myFeature', () => {
  test('does something', () => {});
});

xit('does something', () => {});

// Correct
describe('myFeature', () => {
  test('does something', () => {});
});

Ensuring tests contain assertions

This rule ensures that test blocks contain at least one assertion call, which is necessary for a meaningful test.

/* eslint jest/expect-expect: "error" */

// Incorrect
test('does something', () => {
  // no assertions
});

// Correct
test('does something', () => {
  expect(something).toBe(true);
});

Disallowing identical titles

This rule disallows using the same title for multiple test cases or `describe` blocks, which can cause confusion when trying to identify tests.

/* eslint jest/no-identical-title: "error" */

// Incorrect
describe('myFeature', () => {
  test('does something', () => {});
  test('does something', () => {});
});

// Correct
describe('myFeature', () => {
  test('does something', () => {});
  test('does something else', () => {});
});

Other packages similar to eslint-plugin-jest

Keywords

FAQs

Package last updated on 05 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc