jest/no-unneeded-async-expect-function 스타일
작동 방식
기대하는 프로미스에 대해 불필요한 비동기 함수 래퍼를 금지합니다.
왜 문제가 될까?
비동기 래퍼 내부의 유일한 문장이 await someCall()인 경우, 호출을 expect에 직접 전달해야 합니다. 이렇게 하면 테스트 코드가 더 간결하고 이해하기 쉬워집니다.
예시
이 규칙에 대한 잘못된 코드 예시:
js
await expect(async () => {
await doSomethingAsync();
}).rejects.toThrow();
await expect(async () => await doSomethingAsync()).rejects.toThrow();이 규칙에 대한 올바른 코드 예시:
js
await expect(doSomethingAsync()).rejects.toThrow();이 규칙은 eslint-plugin-vitest와 호환됩니다. 이를 사용하려면 다음 설정을 .oxlintrc.json에 추가하세요:
json
{
"rules": {
"vitest/no-unneeded-async-expect-function": "error"
}
}사용 방법
구성 파일 또는 명령줄 인터페이스에서 이 규칙을 활성화하려면 다음을 사용할 수 있습니다:
json
{
"plugins": ["jest"],
"rules": {
"jest/no-unneeded-async-expect-function": "error"
}
}bash
oxlint --deny jest/no-unneeded-async-expect-function --jest-plugin