-1

I'm using the React Testing Library in an application created using Create React App. am finding that while some of my tests run fine by themselves, if I try and test all at the same time, then they start failing. I wanted to see if running the tests sequentially will get over this issue.

I can see you can run tests inline in jest, but didn't want to eject just to be able to send this parameter thru. I suspect that running all in parallel, is causing some of them to slow down and hence fail and running in series may get over the issue. Appreciate if can share the config to do this.

Mohammad Fared
  • 588
  • 1
  • 7
  • 19
Mickey Puri
  • 835
  • 9
  • 18

1 Answers1

2

Basically you can add more jest options to the react-script test command as following (obviously the option you need here is --runInBand to make the test run sequentially):

package.json

{
  "scripts": {
    "test:runInBand": "react-scripts test --runInBand"
  }
}

Then you run: npm run test:runInBand.

Or you can execute your current test with yarn (yarn would help you to pass the option down to test command), with this way you don't have to create any new script command:

yarn test --runInBand

// npm also offers the same thing by adding `--` to separate the options
// just been aware of that lately via the comment below

npm test -- --runInBand
tmhao2005
  • 14,776
  • 2
  • 37
  • 44