1

I'm using testing-library with react

I have this in my test file

import React from 'react' // best if I can skip this in every test file
import { render, screen } from '@testing-library/react'

but I got this error

`@testing-library/react` import should occur before import of `react`

either I turn off the eslint rule for order or I can somehow skip doing import React in every single test file.

Tina Glenn
  • 85
  • 6

1 Answers1

0

You can include this information in a src/setupTests.js file as follows see this question:

import { React } from 'react';

global.React = React;

If the setupTests.js does not run by default, you might need to modify the "test" property under "scripts" (if you are using that to run your test cases):

"test": "react-scripts test"

Reference: setupTests.js not loading automatically in CRA react app

Hope this helped.

Aastha Bist
  • 324
  • 2
  • 11