-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): add consistent-test-it rule
Fixes #12
- Loading branch information
Showing
7 changed files
with
652 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Have control over `test` and `it` usages (consistent-test-it) | ||
|
||
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`. | ||
|
||
This rule gives you control over the usage of these keywords in your codebase. | ||
|
||
## Rule Details | ||
|
||
This rule can be configured as follows | ||
|
||
```js | ||
{ | ||
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. | ||
|
||
```js | ||
/*eslint jest/consistent-test-it: ["error", {"fn": "test"}]*/ | ||
|
||
test('foo'); // valid | ||
test.only('foo'); // valid | ||
|
||
it('foo'); // invalid | ||
it.only('foo'); // invalid | ||
``` | ||
|
||
```js | ||
/*eslint jest/consistent-test-it: ["error", {"fn": "it"}]*/ | ||
|
||
it('foo'); // valid | ||
it.only('foo'); // valid | ||
|
||
test('foo'); // invalid | ||
test.only('foo'); // invalid | ||
``` | ||
|
||
```js | ||
/*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 | ||
}); | ||
``` | ||
|
||
### Default configuration | ||
|
||
The default configuration forces top level test to use `test` and all tests | ||
nested within describe to use `it`. | ||
|
||
```js | ||
/*eslint jest/consistent-test-it: ["error"]*/ | ||
|
||
test('foo'); // valid | ||
describe('foo', function() { | ||
it('bar'); // valid | ||
}); | ||
|
||
it('foo'); // invalid | ||
describe('foo', function() { | ||
test('bar'); // invalid | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.