Registry / testing / eslint-plugin-mocha

eslint-plugin-mocha

JSON →
library11.2.0jsnpmunverified

ESLint plugin providing rules specific to Mocha test suites, such as enforcing best practices, limiting nested describes, and requiring valid test titles. Current version 11.2.0 (January 2025) with a major breaking change in 11.0.0 that renamed several rules (e.g., *-description to *-title) and switched to ESM-only. The plugin ships TypeScript declarations now. It is maintained and released roughly every few months. Compared to other Mocha linting solutions, this is the official and most widely used plugin with ~1M weekly downloads.

npm install eslint-plugin-mocha
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-MOCH
E
eslint-plugin-mocha
testingjavascriptv11.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import mochaPlugin from 'eslint-plugin-mocha'
const mochaPlugin = require('eslint-plugin-mocha')
ESM-only since v11; CJS require() will fail at runtime
configs
import { configs } from 'eslint-plugin-mocha'
Access flat configs (recommended, all) via named export
rules
import { rules } from 'eslint-plugin-mocha'
Access individual rule definitions for custom configs

Sets up eslint-plugin-mocha with recommended rules and custom overrides using flat config format.

// eslint.config.js (flat config) import mochaPlugin from 'eslint-plugin-mocha'; export default [ mochaPlugin.configs.recommended, { rules: { 'mocha/no-exclusive-tests': 'error', 'mocha/no-nested-tests': 'error', }, }, ];
Debug
Known issues
breakingRules *-description renamed to *-title in v11.0.0 (e.g., valid-suite-description → valid-suite-title)
fix
Update all rule names: replace '-description' with '-title' in configs
affects: >=11.0.0
breakingno-async-describe renamed to no-async-suite in v11.0.0
fix
Replace 'mocha/no-async-describe' with 'mocha/no-async-suite' in your config
affects: >=11.0.0
breakingCommonJS support dropped in v11.0.0 for no-exports rule
fix
Switch to ESM imports or disable the no-exports rule if using CJS
affects: >=11.0.0
breakingSwitched to ESM-only in v11.0.0; require() will fail
fix
Convert your project to ESM or use dynamic import(). Alternatively, pin to v10.x
affects: >=11.0.0
gotchaFlat config format (eslint.config.js) supported from v10.4.0; legacy .eslintrc not supported in v11
fix
Use flat config format. If you need legacy configs, stay on v10.x
affects: >=11.0.0
deprecatedThe 'recommended' config in flat configs is available as mochaPlugin.configs.recommended
fix
Use flat configs for better compatibility moving forward
affects: >=10.5.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported.
Using require() to load eslint-plugin-mocha v11+ which is ESM-only.
fix
Use import statement in an ESM context, or downgrade to v10.x: npm install eslint-plugin-mocha@^10
Configuration for rule "mocha/valid-suite-description" is invalid: Rule has been removed or renamed.
Rule renamed in v11.0.0 from *-description to *-title.
fix
Replace 'mocha/valid-suite-description' with 'mocha/valid-suite-title' in your ESLint config
ESLint couldn't find the plugin "eslint-plugin-mocha" in flat config.
Flat config format not used or plugin not imported correctly.
fix
Import the plugin and spread it in your config array: export default [...mochaPlugin.configs.recommended, ...]
TypeError: Cannot read properties of undefined (reading 'recommended')
Using mochaPlugin.configs.recommended on v10.x without flat config support (v10 prior to 10.4.0).
fix
Update eslint-plugin-mocha to v10.4.0 or later, or use legacy .eslintrc format with v10.x
Upgrade
Version history
11.2.0latest on npm
Audit
Dependencies
eslintrequiredPeer dependency; required to run the plugin
Agent activity
8 hits · last 30 days
node
8
Resources