jeudi 13 février 2020

(node:13276) UnhandledPromiseRejectionWarning: Error: Cannot accept dialog which is already handled

(node:13276) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

Hi guys, I am getting the warning above from the title after I am calling this function 2 times:

async function delete_page(page, page_id) {
  await page.goto('http://127.0.0.1:3000/page/' + page_id,
    { waitUntil: 'domcontentloaded' });

  const navPromise = page.waitForNavigation();
  page.on('dialog', async function(dialog) {
    await dialog.accept();
  });
  await page.click("#delete-page-button");
  await navPromise;
}

I am calling the function delete_page() here:

  after(async function() {
    this.timeout(0);
    await logout(page);
    await login(page, 'AdminTester', 'password');
    await delete_page(page, 'test');
    await delete_page(page, 'test2');
    await logout(page);
    await page.close();
  });

How can I get rid of this warning? Thanks!

Aucun commentaire:

Enregistrer un commentaire