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

后端 未结 16 1495
[愿得一人]
[愿得一人] 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:35

    In my case, this error started appearing randomly and wouldn't go away even after setting a timeout of 30000. Simply ending the process in the terminal and re-running the tests resolved the issue for me. I have also removed the timeout and tests are still passing again.

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

    I would like to add (this is a bit long for a comment) that even with a timeout of 3000 my tests would still sometimes (randomly) fail with

    Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

    Thanks to Tarun's great answer, I think the shortest way to fix a lot of tests is:

    describe('puppeteer tests', () => {
      beforeEach(() => {
        jest.setTimeout(10000);
      });
    
      test('best jest test fest', async () => {
        // Blah
      });
    });
    
    0 讨论(0)
  • 2020-11-28 03:39

    You can also get timeout errors based on silly typos. e.g This seemingly innocuous mistake:

    describe('Something', () => {
      it('Should do something', () => {
        expect(1).toEqual(1)
      })
    
      it('Should do nothing', something_that_does_not_exist => {
        expect(1).toEqual(1)
      })
    })
    

    Produces the following error:

    FAIL src/TestNothing.spec.js (5.427s)
      ● Something › Should do nothing
    
        Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
          
          at node_modules/jest-jasmine2/build/queue_runner.js:68:21
          at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:678:19)
    

    Whilst the code sample posted doesn't suffer from this it might be a cause of failures elsewhere. Also note that I'm not setting a timeout for anything anywhere - either here or the config the 5000ms is just the default setting.

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

    Yet another solution: set the timeout in the jest config file, e.g.:

    { // ... other stuff here
        "testTimeout": 90000
    }
    
    0 讨论(0)
提交回复
热议问题