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

How to run two test commands consecutively using async await? #2

Open
zemingyu opened this issue Mar 18, 2018 · 1 comment
Open

How to run two test commands consecutively using async await? #2

zemingyu opened this issue Mar 18, 2018 · 1 comment

Comments

@zemingyu
Copy link
Owner

zemingyu commented Mar 18, 2018

I need to run these two commands consecutively. How do I make sure it happens in order?

it('can register BokkyPooBah', async () => { await meetupBaseInstance.registerUser("BokkyPooBah", {from: organiser}); assert.equal(await meetupBaseInstance.users.call("BokkyPooBah"), organiser); });

@glamperd
Copy link

I think it will run consecutively more or less as you have it. await causes a wait until the instruction's Promise is resolved, so the assert statement won't start until registerUser has resolved.
For clarity, I'd suggest putting the second await statement in a statement of its own, like this:
await meetupBaseInstance.registerUser("BokkyPooBah", {from: organiser});
const result=await meetupBaseInstance.users.call({ from:organiser });
assert.equal(result[0], "BokkyPooBah");
Note that I've also changed the syntax a little from the original example. It looks more correct to me.

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

2 participants