javascript – Import of mocks in react / jest with the ESLint no-mocks-import rule

So I am a little confused by this rule and I hit a wall while trying to fix it. The description says that I should not import any __mocks__ directories manually. Currently, I have this:

import { Breadcrumbs as BreadcrumbsView } from '../../__mocks__'

Which of course leads to this ESLint error. the __mocks__ has directly subdictionaries and a index.js file which exports all the necessary simulations from these sub-jurisdictions.

The model itself is simple:

import React from 'react'

export const Breadcrumbs = (props) => (

If I do this:


const { Breadcrumbs: BreadcrumbsView } = import('../../__mocks__')

Then this rule passes (not even sure it's even the right solution, because I still have __mocks__ in the way), but the rule import/no-commonjs failed since i used require.

If I use import there instead of require I get the following error when I run the test:

Test suite failed to run

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

Here's what you can do:
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:


var _ref = import('../../__mocks__'),

SyntaxError: Unexpected token import

  at ScriptTransformer._transformAndBuildScript (../../node_modules/jest-runtime/build/script_transformer.js:403:17)

Could someone explain the solution and what am i doing wrong?

Let me also note that I am using Node version 10.13.0. Maybe this is somehow related.