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
.
Why is this bad?
It's a good practice to be consistent in your test suite, so that all tests are written in the same way.
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"
}
}
## How to use
To **enable** this rule in the CLI or using the config file, you can use:
::: code-group
```bash [CLI]
oxlint --deny jest/consistent-test-it --jest-plugin
json
{
"plugins": ["jest"],
"rules": {
"jest/consistent-test-it": "error"
}
}
:::