-
Notifications
You must be signed in to change notification settings - Fork 46
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
ES2016 Async/Await example? #18
Comments
async/await are supported natively in NodeJS since 7.6 https://www.infoq.com/news/2017/02/node-76-async-await Should be included in examples!!! |
Hi @Mr0grog, I am trying your example above for my specs. Finding that it handles requests better but at the end, I'm getting |
In an |
Thanks for the response! I actually have a catch:
I see that console log along with the other error complaint. It appears to be getting stuck during the
Is there some trick to using |
Is your code exactly like the example? What selector are you actually If you had: await nightmare
.something()
.then(() => nightmare.exists('div.app'))
.then(exists => expect(exists).to.equal(true)); Then this should by definition work with wait: await nightmare
.something()
.wait('div.app'); Side note: you can use async function run() {
try {
await nightmare
.something()
.something()
.something();
}
catch (error) {
// handle the error however you like
}
finally {
// cleanup that runs regardless of success or error
await nightmare.end()
}
} |
Yep, that first example does work with wait, but wait with evaluate wouldn't. I was testing this on an app, that goes from
It could be related to issue segment-boneyard/nightmare#1423. Thanks for the side note. Totally new to using async/await. |
Can you try that without attempting to return an element? e.g. here: .evaluate(() => document.querySelector('.dashboard')) You can’t pass elements between the Electron and Node.js processes (only simple values like booleans, strings, numbers, and arrays or objects containing them). Instead, you’d want to do something like: await nightmare
.something()
.wait('.dashboard')
// Note also `querySelector()` returns a single element, not an array
.evaluate(() => !!document.querySelector('.dashboard'))
.then(exists => expect(exists).to.equal(true)); That said, if your problem is actually some unbelievably terrible bug like segment-boneyard/nightmare#1423 appears to be, that won’t help you :P |
Maaaaaybe worth having a page on usage with async functions. While these are still just a proposal, they are being actively worked on for both Chakra Core and V8.
Starting point:
Though it would probably be a good idea to cover how to use it today with Babel, too.
The text was updated successfully, but these errors were encountered: