eslint-plugin-lodash
eslint-plugin-lodash copied to clipboard
lodash/prefer-* rules cause problems with Jest mocks
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.
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?