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

Feature Request: Implement Chaining for Async Matchers #4235

Open
schaable opened this issue Aug 3, 2023 · 2 comments
Open

Feature Request: Implement Chaining for Async Matchers #4235

schaable opened this issue Aug 3, 2023 · 2 comments
Labels
area:chai-matchers status:ready This issue is ready to be worked on type:feature Feature request

Comments

@schaable
Copy link
Member

schaable commented Aug 3, 2023

Describe the feature

The hardhat-chai-matchers plugin currently lacks support for chaining with async matchers such as reverted, revertedWith, changeEtherBalance, etc.

Chaining would enable users to create more expressive and readable assertions by combining multiple matchers, improving the testing experience.

Example of the desired chaining:

await expect(contract.method(...))
  .to.be.revertedWithCustomError(...)
  .and.to.not.changeTokenBalance(...);

As a temporary workaround, you can create separate assertions for each async matcher:

const tx = contract.method(...);
await expect(tx).to.be.revertedWithCustomError(...);
await expect(tx).to.not.changeTokenBalance(...);

If you believe implementing chaining for async matchers would be valuable and beneficial for your testing workflows, please consider upvoting this issue to show your interest and support.

Search terms

No response

@schaable schaable added type:feature Feature request status:ready This issue is ready to be worked on area:chai-matchers labels Aug 3, 2023
@sherpya
Copy link

sherpya commented Aug 11, 2023

I always known there was something strange in my tests :)
perhaps multiple emits looks like can be chained, correct?

@fvictorio
Copy link
Member

Yes, .emit is the only one that can be chained (and only to itself).

@schaable we should update the plugin's readme to add emit to the list of matchers that do not support chaining, and add a clarification saying "The only exception is chaining multiple .emit matchers" or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:chai-matchers status:ready This issue is ready to be worked on type:feature Feature request
Projects
Status: Backlog
Development

No branches or pull requests

4 participants
@sherpya @fvictorio @schaable and others