source: frontend/node_modules/eslint-plugin-jest/docs/rules/no-mocks-import.md

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
3When using `jest.mock`, your tests (just like the code being tested) should
4import from `./x`, not `./__mocks__/x`. Not following this rule can lead to
5confusion, because you will have multiple instances of the mocked module:
6
7```js
8jest.mock('./x');
9const x1 = require('./x');
10const x2 = require('./__mocks__/x');
11
12test('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
19This rule reports imports from a path containing a `__mocks__` component.
20
21Example violations:
22
23```js
24import thing from './__mocks__/index';
25require('./__mocks__/index');
26require('__mocks__');
27```
Note: See TracBrowser for help on using the repository browser.