jest/consistent-test-it Style
What it does
Jest allows you to choose how you want to define your tests, using the it
or the test
keywords, with multiple permutations for each:
- it:
it
,xit
,fit
,it.only
,it.skip
. - test:
test
,xtest
,test.only
,test.skip
.
Example
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
});
Options
This rule can be configured as follows
json5
{
type: "object",
properties: {
fn: {
enum: ["it", "test"],
},
withinDescribe: {
enum: ["it", "test"],
},
},
additionalProperties: false,
}
fn
Decides whether to use test
or it
.
withinDescribe
Decides whether to use test
or it
within a describe
scope.
This rule is compatible with eslint-plugin-vitest, to use it, add the following configuration to your .eslintrc.json
:
json
{
"rules": {
"vitest/consistent-test-it": "error"
}
}
## References
- [Rule Source](https://github.com/oxc-project/oxc/blob/5190b7fb280dcd15c6de81717c073b06a161ced6/crates/oxc_linter/src/rules/jest/consistent_test_it.rs)