Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling doesn't work for throw newError() in async function #314

Open
IvanNaumenko opened this issue Nov 16, 2017 · 7 comments
Open

Comments

@IvanNaumenko
Copy link

IvanNaumenko commented Nov 16, 2017

ok, duplicate issue from nightwatch, becouse i don't know who could help...
how to forward my mistake to ERROR and got false in result?

throw new Error('some error');

(async function () {

try {
let tmp =  await kfs(title);
let staticD = tmp.leads.leadID,
getBoolean = compare(staticD, myStr);

if (getBoolean === false) {

console.log("kfs " + getBoolean);
throw new Error('some error');

}else {      
  console.log(`${'etalon'}`);
}

}catch (err){
console.log(err);
}
}) ()

image

@mucsi96
Copy link
Owner

mucsi96 commented Dec 9, 2017

I have created an async example project. https://github.com/mucsi96/nightwatch-cucumber-async-await-example Throwing an exeption in any step definition if catched fine by cucumber.js. So don't see any issue here.

@IvanNaumenko
Copy link
Author

IvanNaumenko commented Dec 13, 2017

It works in steps_definition files but not works if you use assert inside async function
assert_inside_command

@IvanNaumenko
Copy link
Author

Thanks, async error handling works fine in steps_definition, but in page object files works like in screenshot above

@anatoliyarkhipov
Copy link

@IvanNaumenko As I can see in the code example from the first post in the thread, you intentionally caught the error and logged it to the console without throwing it further. Have you tried to remove the catch statement from your function? 🤔

@IvanNaumenko
Copy link
Author

I've understood my false. Works!

@NinaNinochka
Copy link

Can you pls write the correct way of catching exception?

Thank you

@NinaNinochka
Copy link

I've understood my false. Works!

Can you pls write the correct way of catching exception?

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants