You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

eslint-plugin-proper-tests

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-proper-tests

ESLint rules for writing more proper tests.

2.1.0
latest
Source
npmnpm
Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source
eslint

eslint-plugin-proper-tests

ESLint plugin for writing proper tests

Installation

npm install -D eslint-plugin-proper-tests

[!NOTE]
For @typescript-eslint v7 use version ^1.0.0 of this plugin. For @typescript-eslint v8 use version ^2.0.0 of this plugin. For ESLint 9 and flat config use version ^2.1.0 of this plugin.

Usage

Flat configuration format:

With flat configuration, use the flat/recommended shared config in your eslint.config.mjs configuration file:

import pluginProperTests from 'eslint-plugin-proper-tests';

export default [
    {
        ...pluginProperTests.configs['flat/recommended']
    },
]

Run ESLint and enjoy the results.

Or, alternatively, add proper-tests to the plugins section of your eslint.config.mjs configuration file and configure the rules one by one:

import pluginProperTests from 'eslint-plugin-proper-tests';

export default [
    {
        plugins: {
            'proper-tests': pluginProperTests,
        },
        rules: {
            "proper-tests/no-useless-matcher-to-be-defined": "error"
            // other rules...
        }
    },
]

Old configuration format:

With old configuration, use the recommended shared config in your .eslintrc configuration file:

module.exports = {
  "extends": ["plugin:proper-tests/recommended"]
}

and you are good to go. Run ESLint and enjoy the results.

Or, alternatively, add proper-tests to the plugins section of your .eslintrc configuration file:

module.exports = {
  "plugins": ["proper-tests"],
  // ...  
}

and configure the rules one by one:

module.exports = {
  "plugins": ["proper-tests"],
  "rules": {
    "proper-tests/no-useless-matcher-to-be-defined": "error"
  }
}

Power of Types

This plugin uses TypeScript to provide more accurate results. To enable this, you need to configure ESLint to work with TypeScript:

Flat configuration format:

import pluginProperTests from 'eslint-plugin-proper-tests';

export default [
    {
        languageOptions: {
            parserOptions: { project: true },
        },
    },
    // ...
]

Old configuration format:

module.exports = {
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": true,
    "tsconfigRootDir": __dirname,
  }
}

If parserOptions is not configured, you will get an error:

Error while loading rule 'proper-tests/no-useless-matcher-to-be-defined': You have used a rule which requires type information, 
but don't have parserOptions set to generate type information for this file

The rules provided by this plugin assume that the files they are checking are test-related. This means it's generally not suitable to include them in your top-level configuration as that applies to all files being linted which can include source files.

Flat configuration format:

For eslint.config.mjs configs you can use the following syntax:

import pluginProperTests from 'eslint-plugin-proper-tests';

export default [
    {
        files: ['**/*.test.ts'], // limit rules to test files only
        ...pluginProperTests.configs['flat/recommended']
    },
]

Old configuration format:

For .eslintrc configs you can use overrides to have ESLint apply additional rules to specific files:

module.exports = {
  "extends": ["eslint:recommended"],
  "overrides": [
    {
      "files": ["test/**"],
      "plugins": ["proper-tests"],
      "extends": ["plugin:proper-tests/recommended"],
      "rules": { "proper-tests/no-useless-matcher-to-be-defined": "off" }
    }
  ],
  "rules": {
    "indent": ["error", 2]
  }
}

Shareable configurations

This plugin exports a recommended configuration that enforces good testing practices.

Flat configuration format:

To enable this configuration with eslint.config.mjs, use the flat/recommended shared config:

import pluginProperTests from 'eslint-plugin-proper-tests';

export default [
    {
        ...pluginProperTests.configs['flat/recommended']
    },
]

Old configuration format:

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

{
  "extends": ["plugin:proper-tests/recommended"]
}

and you are done, no other configuration is needed.

Rules

💼 Configurations enabled in.
☑️ Set in the flat/recommended configuration.
✅ Set in the recommended configuration.

Name                            Description💼
no-long-arrays-in-test-eachDisallow using long arrays with objects inside test.each() or it.each(). Force moving them out of the file.☑️ ✅
no-mixed-expectation-groupsDisallow mixing expectations for different variables between each other.☑️ ✅
no-useless-matcher-to-be-definedDisallow using .toBeDefined() matcher when it is known that variable is always defined.☑️ ✅
no-useless-matcher-to-be-nullDisallow using .toBeNull() when TypeScript types conflict with it.☑️ ✅

In order to use the rules powered by TypeScript type-checking, you must be using @typescript-eslint/parser & adjust your eslint config as outlined here.

eslint-plugin-jest

The main plugin to be installed when Jest is used.

https://github.com/jest-community/eslint-plugin-jest

Keywords

eslint

FAQs

Package last updated on 17 Apr 2025

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