Eslint: ‘React must be in scope when using JSX" – how to handle global variables?

  eslint, javascript, jax, reactjs, testing

I’m running my linting suite and it fills my console with errors like 'React' must be in scope when using JSX for different files…however the issue is that it’s only happening for my test files.

I use the src/setupTests.js file to declare global variables and avoid boilerplate in every test file. Like:

global.React = React;
global.mount = mount;
global.render = render;
global.shallow = shallow;


Is there anyway to update the configuration to be aware of the globals, particularly the React import?

I don’t want to import in every file, use disable rules in every page, or turn ‘off’ this rule for other non-testing files. It’s only a testing suite issue

Source: Ask Javascript Questions