Skip to content
← Back to rules

jest/prefer-to-have-been-called-times 스타일

An auto-fix is available for this rule.

작동 방식

더 나은 실패 메시지를 위해 toHaveBeenCalledTimes는 직접 mock.calls의 길이를 확인하는 것보다 사용되어야 합니다.

왜 좋지 않은가?

이 규칙은 mock.calls의 호출 횟수를 검증할 때 toHaveLength를 사용하면 경고를 발생시킵니다.

예제

이 규칙에 부적절한 코드 예제:

js
expect(someFunction.mock.calls).toHaveLength(1);
expect(someFunction.mock.calls).toHaveLength(0);
expect(someFunction.mock.calls).not.toHaveLength(1);

이 규칙에 적절한 코드 예제:

js
expect(someFunction).toHaveBeenCalledTimes(1);
expect(someFunction).toHaveBeenCalledTimes(0);
expect(someFunction).not.toHaveBeenCalledTimes(0);
expect(uncalledFunction).not.toBeCalled();
expect(method.mock.calls[0][0]).toStrictEqual(value);

사용 방법

구성 파일 또는 명령줄 인터페이스에서 이 규칙을 활성화하려면 다음을 사용할 수 있습니다:

json
{
  "plugins": ["jest"],
  "rules": {
    "jest/prefer-to-have-been-called-times": "error"
  }
}
bash
oxlint --deny jest/prefer-to-have-been-called-times --jest-plugin

참고 자료