用操纵up执行Jest测试时超时错误

时间:2020-05-01 04:55:16

标签: node.js reactjs testing jestjs puppeteer

有一个基于Puppeteer和Jest的小型测试套件,我无法摆脱以下问题

× test page header logo (5019ms)

  ● test page header logo

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

      at node_modules/jest-jasmine2/build/queue_runner.js:72:21   
      at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:633:19)

测试代码

test("test page header logo", async () => {

  const browser = await puppeteer.launch({ headless: false });

  const page = await browser.newPage();

  await page.goto("localhost:3000"); // our react app;

  const text = await page.$eval("a.brand-logo", (el) => el.innerHTML);

  expect(text).toEqual("Logo");
});


1 个答案:

答案 0 :(得分:0)

您应该done test("test page header logo", async (done) => {并在上一个expect expect(text).toEqual("Logo"); done();之后运行完成功能