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

Missing await outside of expect should probably error or warn the user #713

Open
biddls opened this issue Apr 24, 2022 · 1 comment
Open

Comments

@biddls
Copy link

biddls commented Apr 24, 2022

I often run into the issue where I often forget where the await is supposed to be

e.g.
this is how its supposed to be:
if I'm expecting "foo" to be emitted this will fail
await expect (contFoo.foo()).to.emit(contFoo, "fooEvent").withArgs('not FOO')
but if I misplace the await like so
expect (await contFoo.foo()).to.emit(contFoo, "fooEvent").withArgs('not FOO')
this will pass, and I get no error message of any kind, or a hint that I might have misplaced the await

So I'm wondering if a warning could be spat out instead of giving a false pass?
thanks

@rzadp rzadp changed the title misplacing the await for a emit with args should probably error or warn the user Missing await outside of expect should probably error or warn the user Jul 29, 2022
@rzadp
Copy link
Contributor

rzadp commented Jul 29, 2022

Please note that this options (2 awaits):
await expect (await contFoo.foo()).to.emit(contFoo, "fooEvent").withArgs('not FOO')
will correctly catch the error, and this one (0 awaits):
expect (contFoo.foo()).to.emit(contFoo, "fooEvent").withArgs('not FOO')
will give a false pass.

So it's not a problem of a misplaced await, it's a problem of a missing the left-most await outside of the expect.

I suspect the problem is with mocha finishing the tests and exiting with success, even though our expect is still being executed. I'm not sure we can do anything with this with our current implementation - but I will leave the issue in case anyone else has some idea.

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