jestjsts-jest

Configure jest timeout once for all tests


According to the docs one can increase the default async timeout from 5000ms using the jest-object

More specifically, by using the jestsettimeouttimeout

The issue I am facing is I am running a series of tests against an API that is very slow, 5-15 second response times, configuring this jest object at the top of each test is painfully annoying.

Is it possible to declare these settings once before all test files are run?


Solution

  • OK, putting bits together:

    The Jest search box doesn't actually return anything when you search for: setupFilesAfterEnv

    And docs talk about: setupTestFrameworkScriptFile (which also doesn't return anything on the search:/ )

    Anyway, the docs leave you scratching your head but this works:

    jest.config.js:

    module.exports = {
      setupFilesAfterEnv: ['./setup.js'],
    

    setup.js:

    jest.setTimeout(10000); // in milliseconds
    

    The jest folks should make it easier to find this information.