|
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:
731 bytes
|
| Line | |
|---|
| 1 | # Disallow manually importing from `__mocks__` (`no-mocks-import`)
|
|---|
| 2 |
|
|---|
| 3 | When using `jest.mock`, your tests (just like the code being tested) should
|
|---|
| 4 | import from `./x`, not `./__mocks__/x`. Not following this rule can lead to
|
|---|
| 5 | confusion, because you will have multiple instances of the mocked module:
|
|---|
| 6 |
|
|---|
| 7 | ```js
|
|---|
| 8 | jest.mock('./x');
|
|---|
| 9 | const x1 = require('./x');
|
|---|
| 10 | const x2 = require('./__mocks__/x');
|
|---|
| 11 |
|
|---|
| 12 | test('x', () => {
|
|---|
| 13 | expect(x1).toBe(x2); // fails! They are both instances of `./__mocks__/x`, but not referentially equal
|
|---|
| 14 | });
|
|---|
| 15 | ```
|
|---|
| 16 |
|
|---|
| 17 | ### Rule details
|
|---|
| 18 |
|
|---|
| 19 | This rule reports imports from a path containing a `__mocks__` component.
|
|---|
| 20 |
|
|---|
| 21 | Example violations:
|
|---|
| 22 |
|
|---|
| 23 | ```js
|
|---|
| 24 | import thing from './__mocks__/index';
|
|---|
| 25 | require('./__mocks__/index');
|
|---|
| 26 | require('__mocks__');
|
|---|
| 27 | ```
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.