jest/prefer-to-have-length 스타일
작동 방식
오브젝트의 길이 속성에 대한 예측을 검증할 때 더 나은 실패 메시지를 위해 toHaveLength()를 사용해야 합니다.
왜 좋지 않은가?
toBe(), toEqual() 또는 toStrictEqual()가 오브젝트의 길이 속성을 검증하는 데 사용될 경우, 이 규칙은 경고를 발생시킵니다.
예시
이 규칙에 부적절한 코드 예시:
javascript
expect(files["length"]).toBe(1);
expect(files["length"]).toBe(1);
expect(files["length"])["not"].toBe(1);이 규칙에 적절한 코드 예시:
javascript
expect(files).toHaveLength(1);이 규칙은 eslint-plugin-vitest와 호환됩니다. 이를 사용하려면 .oxlintrc.json에 다음 구성 설정을 추가하세요:
json
{
"rules": {
"vitest/prefer-to-have-length": "error"
}
}사용 방법
구성 파일이나 명령줄 인터페이스를 통해 이 규칙을 활성화하려면 다음을 사용할 수 있습니다:
json
{
"plugins": ["jest"],
"rules": {
"jest/prefer-to-have-length": "error"
}
}bash
oxlint --deny jest/prefer-to-have-length --jest-plugin