Jon
Jon

Reputation: 8511

How to set JestJS global timeout in package.json

I am wondering how would I set up a global timeout for all my JestJS tests within package.json?

The default 5000ms is not sufficient for my tests. I don't want to be doing the following code for each of my tests:

it('should return foo', () => { .. }, timeout);

Upvotes: 6

Views: 5439

Answers (1)

Teneff
Teneff

Reputation: 32158

You can add testTimeout to your jest configuration

package.json
"jest": {
  "testTimeout": 10000,
}

or as a CLI option

package.json
"scripts": {
  "test": "jest --testTimeout=10000"
}

If you get the following warning

● Validation Warning:

Unknown option "testTimeout" with value 10000 was found. This is probably a typing mistake. Fixing it will remove this message.

you should upgrade jest

Upvotes: 11

Related Questions