Message “Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout”

后端 未结 16 1493
[愿得一人]
[愿得一人] 2020-11-28 02:56

I\'m using Puppeteer and Jest to run some front end tests.

My tests look as follows:

describe("Profile Ta         


        
相关标签:
16条回答
  • 2020-11-28 03:25

    The timeout you specify here needs to be shorter than the default timeout.

    The default timeout is 5000 and the framework by default is jasmine in case of jest. You can specify the timeout inside the test by adding

    jest.setTimeout(30000);
    

    But this would be specific to the test. Or you can set up the configuration file for the framework.

    Configuring Jest

    // jest.config.js
    module.exports = {
      // setupTestFrameworkScriptFile has been deprecated in
      // favor of setupFilesAfterEnv in jest 24
      setupFilesAfterEnv: ['./jest.setup.js']
    }
    
    // jest.setup.js
    jest.setTimeout(30000)
    

    See also these threads:

    setTimeout per test #5055

    Make jasmine.DEFAULT_TIMEOUT_INTERVAL configurable #652

    P.S.: The misspelling setupFilesAfterEnv (i.e. setupFileAfterEnv) will also throw the same error.

    0 讨论(0)
  • 2020-11-28 03:25

    For Jest 24.9+ we just need to add --testTimeout in the command line

    --testTimeout= 10000 // timeout of 10s
    

    The default timeout value is 5000. This will be applicable for all test cases.

    or if you want to give timeout to particular function only then you can use this syntax while declaring the test case.

    test(name, fn, timeout)
    

    example

    test('example', async () => {
      
    
    }, 10000); // timeout of 10s (default is 5000)
    
    0 讨论(0)
  • 2020-11-28 03:28

    For those who are looking for an explanation about jest --runInBand, you can go to the documentation.

    Running Puppeteer in CI environments

    GitHub - smooth-code/jest-puppeteer: Run your tests using Jest & Puppeteer

    0 讨论(0)
  • 2020-11-28 03:29

    For Jest 24.9+, you can also set the timeout from the command line by adding --testTimeout.

    Here's an excerpt from its documentation:

    --testTimeout=<number>
    Default timeout of a test in milliseconds. Default value: 5000.

    0 讨论(0)
  • 2020-11-28 03:29

    I recently ran into this issue for a different reason: I was running some tests synchronously using jest -i, and it would just timeout. For whatever reasoning, running the same tests using jest --runInBand (even though -i is meant to be an alias) doesn't time out.

    Maybe this will help someone ¯\_(:/)_/¯

    0 讨论(0)
  • 2020-11-28 03:31

    This is a relatively new update, but it is much more straight forward. If you are using Jest 24.9.0 or higher you can just add testTimeout to your config:

    // in jest.config.js
    module.exports = {
      testTimeout: 30000
    }
    
    0 讨论(0)
提交回复
热议问题