jest/prefer-to-have-been-called
eslint-plugin-jest
Safe autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-to-have-been-called": "error",
},
},
];expect(mock).toHaveBeenCalledTimes(0);
expect(mock).toBeCalledTimes(0);
expect(mock).not.toHaveBeenCalledTimes(0);expect(mock).not.toHaveBeenCalled();
expect(mock).toHaveBeenCalled();
expect(mock).toHaveBeenCalledTimes(1);Examples from the Oxlint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
jest/prefer-to-have-been-called
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-to-have-been-called": "error",
},
},
];jest/prefer-to-have-been-called
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/prefer-to-have-been-called": "error"
}
}nursery/useExpectToHaveBeenCalled
nursery · since 2.6.8
{
"linter": {
"rules": {
"nursery": {
"useExpectToHaveBeenCalled": "error"
}
}
}
}Suggest using toHaveBeenCalledTimes()
Require test cases and hooks to be inside a describe block