mocha/consistent-interface
July 16, 2026 ยท View on GitHub
๐ Enforces consistent use of mocha interfaces.
๐ซ This rule is disabled in the โ
recommended config.
๐ง This rule is automatically fixable by the --fix CLI option.
Mocha has several interfaces such as BDD, TDD, Require, Exports, and QUnit. This plugin supports Mocha's BDD, TDD, and Require interfaces.
It does not support Mocha's Exports or QUnit interfaces, or third-party UIs with different syntax. Many rules depend on suite, test, and hook calls being represented as nested call expressions, which those interfaces do not provide consistently.
Usually Mocha injects the variables and functions of the selected interface into the global scope. When using the Require interface, named imports from mocha are used instead. This rule enforces a consistent BDD or TDD interface for imported Mocha interface methods, and it also reports imported Mocha interface methods when settings.mocha.interface is configured for globals.
Options
Example of a custom rule configuration:
rules: {
"mocha/consistent-interface": ["error", { interface: 'BDD' }]
},
where:
interfacecan be set to eitherTDDorBDD
Rule Details
With settings.mocha.interface: "require", this rule enforces that imported Mocha interface methods all belong to the configured BDD or TDD interface.
With settings.mocha.interface: "BDD" or settings.mocha.interface: "TDD", this rule reports named imports of Mocha interface methods from mocha, because those imports indicate require-style usage and can prevent other rules from recognizing Mocha calls.
The autofix is intentionally limited to direct named imports such as import { describe } from 'mocha'. Aliased imports and mixed default imports are still reported, but they are left for manual cleanup.
When Not To Use It
If you do not want to enforce whether Mocha interface methods come from globals or named mocha imports, then you can leave this rule disabled.