Skip to content

jest/no-mocks-import Style

What it does

This rule reports imports from a path containing a mocks component.

Why is this bad?

Manually importing mocks from a __mocks__ directory can lead to unexpected behavior.

Example

Examples of incorrect code for this rule:

ts
import thing from "./__mocks__/index";
require("./__mocks__/index");

Examples of correct code for this rule:

ts
import thing from "thing";
require("thing");

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny jest/no-mocks-import --jest-plugin
json
{
  "plugins": ["jest"],
  "rules": {
    "jest/no-mocks-import": "error"
  }
}

References

Released under the MIT License.