| 1 | # Disallow disabled tests (`no-disabled-tests`)
|
|---|
| 2 |
|
|---|
| 3 | Jest has a feature that allows you to temporarily mark tests as disabled. This
|
|---|
| 4 | feature is often helpful while debugging or to create placeholders for future
|
|---|
| 5 | tests. Before committing changes we may want to check that all tests are
|
|---|
| 6 | running.
|
|---|
| 7 |
|
|---|
| 8 | This rule raises a warning about disabled tests.
|
|---|
| 9 |
|
|---|
| 10 | ## Rule Details
|
|---|
| 11 |
|
|---|
| 12 | There are a number of ways to disable tests in Jest:
|
|---|
| 13 |
|
|---|
| 14 | - by appending `.skip` to the test-suite or test-case
|
|---|
| 15 | - by prepending the test function name with `x`
|
|---|
| 16 | - by declaring a test with a name but no function body
|
|---|
| 17 | - by making a call to `pending()` anywhere within the test
|
|---|
| 18 |
|
|---|
| 19 | The following patterns are considered warnings:
|
|---|
| 20 |
|
|---|
| 21 | ```js
|
|---|
| 22 | describe.skip('foo', () => {});
|
|---|
| 23 | it.skip('foo', () => {});
|
|---|
| 24 | test.skip('foo', () => {});
|
|---|
| 25 |
|
|---|
| 26 | describe['skip']('bar', () => {});
|
|---|
| 27 | it['skip']('bar', () => {});
|
|---|
| 28 | test['skip']('bar', () => {});
|
|---|
| 29 |
|
|---|
| 30 | xdescribe('foo', () => {});
|
|---|
| 31 | xit('foo', () => {});
|
|---|
| 32 | xtest('foo', () => {});
|
|---|
| 33 |
|
|---|
| 34 | it('bar');
|
|---|
| 35 | test('bar');
|
|---|
| 36 |
|
|---|
| 37 | it('foo', () => {
|
|---|
| 38 | pending();
|
|---|
| 39 | });
|
|---|
| 40 | ```
|
|---|
| 41 |
|
|---|
| 42 | These patterns would not be considered warnings:
|
|---|
| 43 |
|
|---|
| 44 | ```js
|
|---|
| 45 | describe('foo', () => {});
|
|---|
| 46 | it('foo', () => {});
|
|---|
| 47 | test('foo', () => {});
|
|---|
| 48 |
|
|---|
| 49 | describe.only('bar', () => {});
|
|---|
| 50 | it.only('bar', () => {});
|
|---|
| 51 | test.only('bar', () => {});
|
|---|
| 52 | ```
|
|---|
| 53 |
|
|---|
| 54 | ### Limitations
|
|---|
| 55 |
|
|---|
| 56 | The plugin looks at the literal function names within test code, so will not
|
|---|
| 57 | catch more complex examples of disabled tests, such as:
|
|---|
| 58 |
|
|---|
| 59 | ```js
|
|---|
| 60 | const testSkip = test.skip;
|
|---|
| 61 | testSkip('skipped test', () => {});
|
|---|
| 62 |
|
|---|
| 63 | const myTest = test;
|
|---|
| 64 | myTest('does not have function body');
|
|---|
| 65 | ```
|
|---|