Skip to content

Difference between position of await when "expect" is used #1749

Answered by krakxn
pajserb0y asked this question in Q&A
Discussion options

You must be logged in to vote

This one is slightly incorrect:

      expect(await nftMarketplace.cancelListing(basicNft.address, TOKEN_ID)).to.emit("ItemCanceled")

This is the apt one:

       await expect( nftMarketplace.cancelListing(basicNft.address,TOKEN_ID)).to.be.revertedWith("NotOwner")})

Why it's incorrect? Because it is plausible for another statement to be executed before the await keyword gets triggered in the first place. And to remove that possibility it is best advised to follow using the await keyword before the statement.

Of course, you can use double awaits here if cancelListing is something which could be inconsistent, but I would not recommend following solely the second method (await inside), it is b…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by pajserb0y
Comment options

You must be logged in to vote
2 replies
@pajserb0y
Comment options

@krakxn
Comment options

Comment options

You must be logged in to vote
2 replies
@pajserb0y
Comment options

@alymurtazamemon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants