eslint-plugin-lodash icon indicating copy to clipboard operation
eslint-plugin-lodash copied to clipboard

lodash/prefer-* rules cause problems with Jest mocks

Open jamesarosen opened this issue 3 years ago • 1 comments

The lodash/prefer-* rules, notably lodash/prefer-noop, cause issues with Jest Mocks.

For example:

import noop from 'lodash/noop'

jest.mock('./widget', () => ({
  __esModule: true,
  default: noop,
}))

This causes the error

The module factory of “jest.mock()” is not allowed to reference any out-of-scope variables.

The problem is that jest.mock can't reference the imported noop.

jamesarosen avatar Aug 05 '22 20:08 jamesarosen

This isn't hard to fix manually:

// .eslintrc.js
{
  overrides: [
    files: ['server/**/*.test.js'],
    rules: {
      'lodash/prefer-noop': 0,
    }
  ]
}

I'm wondering whether that should be in the default eslint-config. What do others think?

jamesarosen avatar Aug 05 '22 20:08 jamesarosen