jest/consistent-test-it 風格
功能
Jest 允許你選擇如何定義你的測試,使用 it
或 test
關鍵字,每個都有多種變化。
- it:
it
,xit
,fit
,it.only
,it.skip
。 - test:
test
,xtest
,test.only
,test.skip
。
範例
javascript
/*eslint jest/consistent-test-it: ["error", {"fn": "test"}]*/
test("foo"); // valid
test.only("foo"); // valid
it("foo"); // invalid
it.only("foo"); // invalid
javascript
/*eslint jest/consistent-test-it: ["error", {"fn": "it"}]*/
it("foo"); // valid
it.only("foo"); // valid
test("foo"); // invalid
test.only("foo"); // invalid
javascript
/*eslint jest/consistent-test-it: ["error", {"fn": "it", "withinDescribe": "test"}]*/
it("foo"); // valid
describe("foo", function () {
test("bar"); // valid
});
test("foo"); // invalid
describe("foo", function () {
it("bar"); // invalid
});
選項
此規則可配置如下:
json5
{
type: "object",
properties: {
fn: {
enum: ["it", "test"],
},
withinDescribe: {
enum: ["it", "test"],
},
},
additionalProperties: false,
}
fn
決定使用 test
或 it
。
withinDescribe
決定在 describe
範圍內使用 test
或 it
。
此規則與 eslint-plugin-vitest 相容,要使用它,請將以下設定新增至您的 .eslintrc.json
json
{
"rules": {
"vitest/consistent-test-it": "error"
}
}
## References
- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/jest/consistent_test_it.rs)