I'm trying to test for an alert box in Puppeteer:
msg = '';
await page.goto('http://localhost:8080/', {
waitUntil: 'networkidle2'
});
await page.$eval('#value', el => el.value = '<script>alert("BLEH")</script>');
page.on('dialog', async dialog => {
msg = dialog.message();
await dialog.dismiss()
})
// submit comment
await page.$eval('#message', form => form.submit());
expect(msg).toEqual('BLEH');
However, it doesn't seem to return the message inside the alert box (even though I've confirmed it works doing it manually). Any ideas why page.on('dialog', async dialog => { isn't being entered?