-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow eslint-plugin-jest to recognize more disabled tests #4533
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly didn't realize we exposed this global…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to admit I wasn't even aware of it myself until I checked out the docs for Jasmine