| 1 | # Disallow focused tests (`no-focused-tests`)
|
|---|
| 2 |
|
|---|
| 3 | Jest has a feature that allows you to focus tests by appending `.only` or
|
|---|
| 4 | prepending `f` to a test-suite or a test-case. This feature is really helpful to
|
|---|
| 5 | debug a failing test, so you don’t have to execute all of your tests. After you
|
|---|
| 6 | have fixed your test and before committing the changes you have to remove
|
|---|
| 7 | `.only` to ensure all tests are executed on your build system.
|
|---|
| 8 |
|
|---|
| 9 | This rule reminds you to remove `.only` from your tests by raising a warning
|
|---|
| 10 | whenever you are using the exclusivity feature.
|
|---|
| 11 |
|
|---|
| 12 | ## Rule Details
|
|---|
| 13 |
|
|---|
| 14 | This rule looks for every `describe.only`, `it.only`, `test.only`, `fdescribe`,
|
|---|
| 15 | and `fit` occurrences within the source code. Of course there are some
|
|---|
| 16 | edge-cases which can’t be detected by this rule e.g.:
|
|---|
| 17 |
|
|---|
| 18 | ```js
|
|---|
| 19 | const describeOnly = describe.only;
|
|---|
| 20 | describeOnly.apply(describe);
|
|---|
| 21 | ```
|
|---|
| 22 |
|
|---|
| 23 | The following patterns are considered warnings:
|
|---|
| 24 |
|
|---|
| 25 | ```js
|
|---|
| 26 | describe.only('foo', () => {});
|
|---|
| 27 | it.only('foo', () => {});
|
|---|
| 28 | describe['only']('bar', () => {});
|
|---|
| 29 | it['only']('bar', () => {});
|
|---|
| 30 | test.only('foo', () => {});
|
|---|
| 31 | test['only']('bar', () => {});
|
|---|
| 32 | fdescribe('foo', () => {});
|
|---|
| 33 | fit('foo', () => {});
|
|---|
| 34 | fit.each`
|
|---|
| 35 | table
|
|---|
| 36 | `();
|
|---|
| 37 | ```
|
|---|
| 38 |
|
|---|
| 39 | These patterns would not be considered warnings:
|
|---|
| 40 |
|
|---|
| 41 | ```js
|
|---|
| 42 | describe('foo', () => {});
|
|---|
| 43 | it('foo', () => {});
|
|---|
| 44 | describe.skip('bar', () => {});
|
|---|
| 45 | it.skip('bar', () => {});
|
|---|
| 46 | test('foo', () => {});
|
|---|
| 47 | test.skip('bar', () => {});
|
|---|
| 48 | it.each()();
|
|---|
| 49 | it.each`
|
|---|
| 50 | table
|
|---|
| 51 | `();
|
|---|
| 52 | test.each()();
|
|---|
| 53 | test.each`
|
|---|
| 54 | table
|
|---|
| 55 | `();
|
|---|
| 56 | ```
|
|---|