【问题标题】:How to set a max timeout for Jest test running Puppeteer?如何为运行 Puppeteer 的 Jest 测试设置最大超时?
【发布时间】:2018-04-25 23:05:58
【问题描述】:

尝试查看文档,但没有找到为测试用例设置最大超时的方法。似乎是一个简单的功能。

import puppeteer from 'puppeteer'

test('App loads', async() => {
  const browser = await puppeteer.launch({ headless: false, slowMo: 250 });
  const page = await browser.newPage();
  await page.goto('http://localhost:3000');
  await browser.close();
});

【问题讨论】:

    标签: jestjs puppeteer


    【解决方案1】:

    Jest's test(name, fn, timeout) function 可以采用指定自定义超时的第三个参数。

    test('example', async () => {
      ...
    }, 1000); // timeout of 1s (default is 5s)
    

    来源:https://github.com/facebook/jest/issues/5055#issuecomment-350827560

    【讨论】:

      【解决方案2】:

      您还可以在 beforeAll() 函数中使用 jest.setTimeout(10000); 为套件全局设置超时:

      beforeAll(async () => {
      
          jest.setTimeout(10000); // change timeout to 10 seconds
      
      });
      

      【讨论】:

        猜你喜欢
        • 2018-11-28
        • 2021-10-15
        • 1970-01-01
        • 1970-01-01
        • 2018-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-18
        相关资源
        最近更新 更多