-
-
Notifications
You must be signed in to change notification settings - Fork 698
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: .change/.increases etc with a function for value #544
Comments
Hey @elado thanks for the issue. If you'd like to make a PR for this feature I'd happily review it with a view to merging 😄. You'll need to modify the assertChanges assertion, as well as assertIncreases, and assertDecreases. Documentation is above each method (here's the assertchanges docs) - that will need updating with examples. Finally, extra tests will be needed to cover this, in all three interfaces: assert, expect, and should. I look forwarding to seeing what you come up with 😀 |
Hi @keithamus, I'm ready to tackle this one, can I or is anyone else already working on this? |
Hey @lucasfcosta - no one else has come forward to implement it, so it'd be awesome if you do! Also, I think it's important that @timruffles and @matthijsgroen are involved in this process (if they want to be) - as this overlaps a lot of the functionality from their plugins (aside: there's a larger issue here about chai plugins being subsumed as chai evolves - |
Ah, okay, I totally understand, that issue explains the whole situation pretty well (and I think chai is in the right track here). I will take a look at the code today and as soon as I've got a "draft" I will post it here so that @timruffles and @matthijsgroen can take a look, do further improvements and share their opinions on it. Thanks for your help! |
Looks good so far. What my experience is that I used the Or else the value of merging the 2 plugins in the core is a bit lost on me. |
@matthijsgroen Promises is something I'd like chai to support, but in the right way. For example, in my experience, async/await pretty much eliminates the need for Promise support in chai. (Ninjaedit:) My point is we need to have a way to deal with promises with one wholesale pattern, that works for all assertions. Chai-as-promised demonstrates that possibility. I'm slightly weary of adding such generic assertions as I know all of that seems not very positive, but I really do want to accommodate those use cases, but in a way that makes sense to the whole of chai. |
I agree, but from the discussion in #339, the readability is more valuable than having some generic words around. What I understood when making these plugins is that these words are only allowed within certain chains, so this would protect people from making weird sentences no? And I am happy to see an example of how this change thing would work with a promise. To be honest I wrote the plugins a while ago, still use them daily but I do not update the entire test stack daily to make use of all new plugins and constructs. I'm not sceptical, I would love to have proper support in the core for these behaviours, but it should be there in a manner that would eliminate the need for change plugins instead of adding a 3rd option. |
Well, I've already got |
@lucasfcosta let's tackle it in a separate PR 😄 |
Ah ok, I think the my PR has everything we need then |
This one is done! |
LGTM |
//
chai-change
plugin doesn't seem to work anymore (chaijs/chai-change#4)Seems like
assertChanges
inassertions.js
expectsobject, prop
. It limits the usage of this kind of assertion, as I can't do:It's good in cases I use immutable data, and
getSomething
returns different object completely.RSpec's
change
matcher has this feature, it can get either an object and a method name or a function for more arbitrary operations.https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/change-matcher
The text was updated successfully, but these errors were encountered: