0

I came across one big issue combining puppeteer with jest. Whenever I hit "npm run test" this test fails displaying: "Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.". This warning also appears even if I pass timeout as a third argument to test function or calling jest.setTimeout(timeout) from inside of beforeEach method callback. What the problem is there, could you guys help me with this. P.S. I'm using jest and puppeteer packages separately

const pup = require('puppeteer')

let browser, page

beforeEach(async _ => {
  browser = await pup.launch({ 
    headless: false  
  })
  page = await browser.newPage()
  await page.goto('localhost:3000')
})

afterEach(async _ => await browser.close())

test('Login function', async _ => {
  await page.click('link')

  const url = await page.url()

  expect(url).toMatch(/accounts\.google\.com/)
})
4

1 回答 1

0

在 Mocha 和 Jest 中,它看起来大多相同。当您运行执行时间超过默认超时的异步脚本时,您必须手动覆盖默认超时。

test('Login function', async _ => {
 //..
}, 60000);

或者,您可以使用以下命令通过 CLI覆盖测试的全局超时:

--testTimeout=<number>
于 2020-11-28T23:49:26.617 回答