-
-
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
Change function for value #607
Change function for value #607
Conversation
bea1f28
to
e778cee
Compare
Good work @lucasfcosta 👍 |
Is there any discussion of supporting functions as in https://github.com/timruffles/chai-change, or would chai-change override if used? |
This PR adds function support. It seems like we're basically going to be folding in chai-change's featureset - not something with initially planned for though. |
I just read through the PR code more thoroughly, thanks for adding this. |
It'd be good to support functions as obviously in node we test stuff that's async. e.g |
It's a shame the original chai-change code couldn't be used as it supported all of this, and had tests. Totally put off contributing by: 1) being told to put something in a plugin, 2) then having chai override it and breaking compat with the plugin 3) and finally now, having a version without all the features added not using the original, working, testing, feature complete code that @matthijsgroen or I wrote :/ |
@timruffles please read #605. Understand this was not an intentional thing that happened, and we'd definitely like to fold in the features from chai-change and chai-changes, in a way that is idiomatic to Chai core. If you'd like, we could discuss this properly over something like Skype or Google Hangouts? |
I would like to contribute, but not sure what exactly you need from me :-) (all code is open source anyway ;-)) I haven't upgraded Chai in a while, so my tests are stable at the moment. If you need something from me, please let me know. I agree with the approach of having Chai support all basic structures of Javascript out of the box. And I hope asynchronous behaviour will be supported everywhere, but more than that opinion (which you guys already know) I am not able to add at the moment :-) Thanks for adding me to the group! |
I must agree with @timruffles here; even if the effort put by the authors of chai-change(s) was duplicated, it's pretty bad that Chai basically overwrites those plugins. Users are left with little option now... It seems the APIs that Chai presents are pretty opinionated, consider this: var x = 0;
assert.changes(function() { x += 1 }, function() { return x }, { by: 1 }); Which yields: AssertionError: expected [Function] to have a property { by: 1 } I don't understand the decision that the modifier must return an object - what's the point of defining the getter? I think in the above scenario the user would expect that the expectations ( If I find the time and you guys are willing to accept a contribution, I'd like to make it so that Chai (as of 3.5.0) allows us to use chai-change and chai-changes (then there'll be no harm done to existing Chai API users and everyone'll be happy - aside of the fragmentation that happened here...) Thoughts? (Thanks to everyone for the great work, needless to say :)) |
Hi @amireh, thanks for your feedback! I'm afraid I didn't understand exactly what you think. What is a "modifier" to you? Is it the function which changes a value? Actually, you don't necessarily need to return an object on the modifier function, you just gotta pass to the assertion the property of which object you expect to change. As you can see here what we do is:
I think Chai's current API already covers the same cases as the chai-change plugin (which is an excellent plugin btw), we just incorporated it's functionalities into Chai keeping our assertion style, which aims to be fluid and as similar to the english language as possible. That example you just posted works for the Please let me know if I misunderstood what you wanted to say. |
Yes! Sorry about the confusion, I think chai-change calls it "affector" - we're talking about the same thing though.
I believe this is the point of my misconception; to me when I used the API, my reasoning was for a function of the following signature:
Was that Maybe I could wrap the output in an object and then it would work, but that seems a bit hackish to me. What I'm proposing (but this would be an API-breaking change) is: should a getter function be passed for a value ( Does that make any sense?
Chai is brilliant, we use it everyday and in every project that is testable - I'd love to contribute if I can. The API itself is engineered towards the common use case which is totally understandable, but it would be nice to give us the low handles when needed, that's all.
I did not know about that assertion, thank you! I'll check out the PR for more hidden goodies. It's too bad that the docs here do not mention |
@amireh thanks for taking your time to explain 😄 Well, the docs there aren't updated because they're generated according to the latest version released on NPM (which is 3.5.0 by now) and this change is going to be released on 4.0.0. The change you proposed really seems useful. Having to assign a variable to an object in order to test it seems a bit hackish indeed. Having the possibility of using a @meeber @keithamus What do you guys think about this? If people agree we can push this forward. I can give you more guidelines to start your work as soon as we get to an agreement with other maintainers here. But basically we would need to check the passed arguments to check if we've got a Thanks for wanting to contribute! Let's keep on rocking 💥 |
Sounds reasonable to me for When documenting this, I'd avoid use of the word |
Personally, I find either When is 4.0.0 planned for release? |
This is my first draft for #544.
(EDIT: I think there's nothing more to be done, I read the code again and it seems to match all the orientations on #544)
assertChanges
,assertIncreases
andassertDecreases
now accept only afunction
as theobject
argument instead of needing bothobject
andprop
I tried to avoid code repetition, but all assertions have basically the same inner workings, so this is the cleanest way I could code them.
Is this looking like what you had expected @keithamus? If it is not feel free to point out the changes you'd like me to make.
@timruffles and @matthijsgroen are also welcome to take a look on this and share their opinions 😃 .