getgauge / taiko

A node.js library for testing modern web applications
https://taiko.dev
MIT License
3.57k stars 453 forks source link

evaluate returns empty object when function throws #2613

Open mmkal opened 2 years ago

mmkal commented 2 years ago

Describe the bug

const x = await evaluate(() => {
  return document.querySelector('.doesNotExist').textContent
})

When no element with class doesNotExist exists x will have value {}. I think this is because it's a json-ified error.

To Reproduce

const { openBrowser, evaluate, goto } = require('taiko');
openBrowser();
goto('https://example.com')
const x = await evaluate(() => {
  return document.querySelector('.doesNotExist').textContent
})
console.log(x);

Expected behavior

evaluate should throw when the client function throws. It might require wrapping the function and returning an either type which includes the message and the stack of the error.