Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 967 Bytes

prefer-to-have-been-called-once.md

File metadata and controls

32 lines (21 loc) · 967 Bytes

Suggest using toHaveBeenCalledOnce() (prefer-to-have-been-called-once)

🔧 This rule is automatically fixable by the --fix CLI option.

For expecting a mock or spy to have been called once, jest-extended provides the toHaveBeenCalledOnce matcher.

Rule details

This rule triggers a warning if an expect assertion is found asserting that a mock or spy is called once using toHaveBeenCalledTimes(1).

The following patterns are considered warnings:

expect(myMock).toHaveBeenCalledTimes(1);
expect(mySpy).not.toHaveBeenCalledTimes(1);

The following patterns are not considered warnings:

expect(myMock).toHaveBeenCalledOnce();
expect(mySpy).not.toHaveBeenCalledOnce();

Further Reading