Skip to content

jest/no-alias-methods Style

🛠️ An auto-fix is available for this rule.

What it does

This rule ensures that only the canonical name as used in the Jest documentation is used in the code.

Why is this bad?

These aliases are going to be removed in the next major version of Jest - see jestjs/jest#13164 for more. This rule will makes it easier to search for all occurrences of the method within code, and it ensures consistency among the method names used.

Example

javascript
expect(a).toBeCalled();
expect(a).toBeCalledTimes();
expect(a).toBeCalledWith();
expect(a).lastCalledWith();
expect(a).nthCalledWith();
expect(a).toReturn();
expect(a).toReturnTimes();
expect(a).toReturnWith();
expect(a).lastReturnedWith();
expect(a).nthReturnedWith();
expect(a).toThrowError();

This rule is compatible with eslint-plugin-vitest, to use it, add the following configuration to your .eslintrc.json:

json
{
  "rules": {
    "vitest/no-alias-methods": "error"
  }
}

How to use

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

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

References

Released under the MIT License.