taiko icon indicating copy to clipboard operation
taiko copied to clipboard

evaluate returns empty object when function throws

Open mmkal opened this issue 3 years ago • 0 comments

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.

mmkal avatar Jul 07 '22 01:07 mmkal