0
votes

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/)
})
1
Is there no other output? Did you try to enable Puppeteer debugging github.com/puppeteer/puppeteer#debugging-tips ? even if I pass timeout as a third argument to test function - only test function and not beforeEach? How much? beforeEach has more chances to fail. 'localhost:3000' - protocol should be specified. 'link' - the selector is wrong. If this doesn't help, consider providing stackoverflow.com/help/mcve that can reproduce the problem.Estus Flask

1 Answers

0
votes

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.

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

Alternative you override the global timeout for your test via CLI by using:

--testTimeout=<number>