jest/consistent-test-it 스타일
작동 방식
Jest는 it 또는 test 키워드를 사용하여 테스트를 정의하는 방식을 선택할 수 있도록 허용하며, 각각에 대해 여러 가지 변형이 있습니다:
- it:
it,xit,fit,it.only,it.skip. - test:
test,xtest,test.only,test.skip.
왜 문제인가요?
테스트 세트에서 일관성을 유지하는 것은 좋은 관습입니다. 이렇게 하면 모든 테스트가 동일한 방식으로 작성됩니다.
예시
javascript
/* jest/consistent-test-it: ["error", {"fn": "test"}] */
test("foo"); // 유효
test.only("foo"); // 유효
it("foo"); // 비유효
it.only("foo"); // 비유효javascript
/* jest/consistent-test-it: ["error", {"fn": "it"}] */
it("foo"); // 유효
it.only("foo"); // 유효
test("foo"); // 비유효
test.only("foo"); // 비유효javascript
/* jest/consistent-test-it: ["error", {"fn": "it", "withinDescribe": "test"}] */
it("foo"); // 유효
describe("foo", function () {
test("bar"); // 유효
});
test("foo"); // 비유효
describe("foo", function () {
it("bar"); // 비유효
});이 규칙은 eslint-plugin-vitest와 호환되며, 이를 사용하려면 .oxlintrc.json에 다음 설정을 추가하세요:
json
{
"rules": {
"vitest/consistent-test-it": "error"
}
}구성
이 규칙은 다음 속성을 가진 구성 객체를 받습니다:
fn
type: "it" | "test"
기본값: "test"
test 또는 it 중 어느 것을 사용할지 결정합니다.
withinDescribe
type: "it" | "test"
기본값: "it"
describe 범위 내부에서 test 또는 it 중 어느 것을 사용할지 결정합니다. fn만 제공된 경우, 이 값은 fn의 값과 동일하게 기본 설정됩니다.
사용 방법
이 규칙을 활성화하기 위해 구성 파일이나 명령줄 인터페이스에서 다음과 같이 사용할 수 있습니다:
json
{
"plugins": ["jest"],
"rules": {
"jest/consistent-test-it": "error"
}
}bash
oxlint --deny jest/consistent-test-it --jest-plugin