|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
992 bytes
|
| Line | |
|---|
| 1 | # Disallow using `exports` in files containing tests (`no-export`)
|
|---|
| 2 |
|
|---|
| 3 | Prevents using `exports` if a file has one or more tests in it.
|
|---|
| 4 |
|
|---|
| 5 | ## Rule Details
|
|---|
| 6 |
|
|---|
| 7 | This rule aims to eliminate duplicate runs of tests by exporting things from
|
|---|
| 8 | test files. If you import from a test file, then all the tests in that file will
|
|---|
| 9 | be run in each imported instance, so bottom line, don't export from a test, but
|
|---|
| 10 | instead move helper functions into a separate file when they need to be shared
|
|---|
| 11 | across tests.
|
|---|
| 12 |
|
|---|
| 13 | Examples of **incorrect** code for this rule:
|
|---|
| 14 |
|
|---|
| 15 | ```js
|
|---|
| 16 | export function myHelper() {}
|
|---|
| 17 |
|
|---|
| 18 | module.exports = function () {};
|
|---|
| 19 |
|
|---|
| 20 | module.exports = {
|
|---|
| 21 | something: 'that should be moved to a non-test file',
|
|---|
| 22 | };
|
|---|
| 23 |
|
|---|
| 24 | describe('a test', () => {
|
|---|
| 25 | expect(1).toBe(1);
|
|---|
| 26 | });
|
|---|
| 27 | ```
|
|---|
| 28 |
|
|---|
| 29 | Examples of **correct** code for this rule:
|
|---|
| 30 |
|
|---|
| 31 | ```js
|
|---|
| 32 | function myHelper() {}
|
|---|
| 33 |
|
|---|
| 34 | const myThing = {
|
|---|
| 35 | something: 'that can live here',
|
|---|
| 36 | };
|
|---|
| 37 |
|
|---|
| 38 | describe('a test', () => {
|
|---|
| 39 | expect(1).toBe(1);
|
|---|
| 40 | });
|
|---|
| 41 | ```
|
|---|
| 42 |
|
|---|
| 43 | ## When Not To Use It
|
|---|
| 44 |
|
|---|
| 45 | Don't use this rule on non-jest test files.
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.