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/)
})
In Mocha and Jest it mostly looks the same. You manually must override the default timeout when you run async scripts that will execute longer than the default timeout.
Alternative you override the global timeout for your test via CLI by using: