-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow eslint-plugin to recognize more disabled tests (#4533)
Already recognizes: * tests that append `skip` (e.g. `it.skip(...)`) * tests that prepend `x` (e.g. `xit(...)`) This change adds: * tests that don't contain a function body * tests that contain a call to `pending()` https://jasmine.github.io/2.0/introduction.html#section-Pending_Specs
- Loading branch information
Showing
5 changed files
with
202 additions
and
82 deletions.
There are no files selected for viewing
43 changes: 37 additions & 6 deletions
43
packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md
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 |
---|---|---|
@@ -1,33 +1,64 @@ | ||
# Disallow Disabled Tests (no-disabled-tests) | ||
|
||
Jest has a feature that allows you to skip tests by appending `.skip` or prepending `x` to a test-suite or a test-case. | ||
Sometimes tests are skipped as part of a debugging process and aren't intended to be committed. This rule reminds you to remove .skip or the x prefix from your tests. | ||
Jest has a feature that allows you to temporarily mark tests as disabled. This | ||
feature is often helpful while debugging or to create placeholders for future | ||
tests. Before committing changes we may want to check that all tests are | ||
running. | ||
|
||
This rule raises a warning about disabled tests. | ||
|
||
## Rule Details | ||
|
||
This rule looks for every `describe.skip`, `it.skip`, `test.skip`, `xdescribe`, `xit` and `xtest` occurrences within the source code. | ||
There are a number of ways to disable tests in Jest: | ||
* by appending `.skip` to the test-suite or test-case | ||
* by prepending the test function name with `x` | ||
* by declaring a test with a name but no function body | ||
* by making a call to `pending()` anywhere within the test | ||
|
||
The following patterns are considered warnings: | ||
|
||
```js | ||
describe.skip('foo', () => {}); | ||
it.skip('foo', () => {}); | ||
test.skip('foo', () => {}); | ||
|
||
describe['skip']('bar', () => {}); | ||
it['skip']('bar', () => {}); | ||
test.skip('foo', () => {}); | ||
test['skip']('bar', () => {}); | ||
|
||
xdescribe('foo', () => {}); | ||
xit('foo', () => {}); | ||
xtest('bar', () => {}); | ||
xtest('foo', () => {}); | ||
|
||
it('bar'); | ||
test('bar'); | ||
|
||
it('foo', () => { | ||
pending() | ||
}); | ||
``` | ||
|
||
These patterns would not be considered warnings: | ||
|
||
```js | ||
describe('foo', () => {}); | ||
it('foo', () => {}); | ||
test('foo', () => {}); | ||
|
||
describe.only('bar', () => {}); | ||
it.only('bar', () => {}); | ||
test('foo', () => {}); | ||
test.only('bar', () => {}); | ||
``` | ||
|
||
### Limitations | ||
|
||
The plugin looks at the literal function names within test code, so will not | ||
catch more complex examples of disabled tests, such as: | ||
|
||
```js | ||
const testSkip = test.skip; | ||
testSkip('skipped test', () => {}); | ||
|
||
const myTest = test; | ||
myTest('does not have function body'); | ||
``` |
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
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