to satisfy: compare functions by value#328
Conversation
|
@sunesimonsen, mind if I land ed4873e on its own? It seems pretty uncontroversial and provides that "escape" in a forwards compatible way, should we end up landing the rest of this (in a fixed up version :). |
93b96db to
f589d8d
Compare
|
Got bitten by this yesterday where I did something like this: expect(myFunction, 'to call the callback with error', httpErrors.BadRequest);The mistake is that To me that serves as a good example of why special casing functions in |
|
I agree, that is too surprising. Let's do it. |
|
@sunesimonsen Cool! Then we just need to figure out how to fix those failing tests. I remember I felt pretty stuck. |
|
I can try to take a look at it. But this weekend is occupied. |
|
Appreciated :) |
|
We should get this rebased and pick it up again. Sorry for never returning to the issue. |
f589d8d to
2686119
Compare
|
Rebased. |
|
... And no worries, this isn't exactly a high priority thing, since it requires a major version bump. |
|
@papandreou the more I think about it the more I think this is a good idea. Question - I believe it should be possible to identify the cases that this change will no longer allow, for the sake of any large user of Unexpected I wonder if we might want to consider a release of v10 that actually warned this will be deprecated in v11? It could be seriously helpful for any large Unexpected user (ourselves at $work included) to check we don't rely on this. And for the record, I guess this is me sort of volunteering.. 🧐 |
❤️ |
|
I don't think the deprecation is a good idea now that we have a way forward and then we can remove the functionality in v11. |
0f5080a to
76259d2
Compare
…re the functions with === instead of executing the RHS one with the LHS one as the argument. (Breaking!)
76259d2 to
930431c
Compare
81afefc to
8b0cd9d
Compare
|
@papandreou I'm pretty sure that we need to be able to detect when an |
a41800b to
d14d14b
Compare
|
@sunesimonsen, thanks, looking forward to it! (Kinda relieved that it wasn't easy :) |
|
Mhh this is more complicated than I though, you can in principal do this: expect({ foo: 'text' }, 'to satisfy', {
foo: expect.it('to be a string').and(v => expect(v, 'to match', /ext$/))
}) |
|
Hmm, yeah, you're right. We've supported that since 10.28.0 due to b562c46 It's probably a well kept secret, so I think we can consider unsupporting it if it makes this really hard. |
d14d14b to
8b0cd9d
Compare
|
@papandreou what I'm trying to get at, is that you can basically do anything, so it is kind of hard to inline the diff - and know when that is the right thing to do. I'm actually a little puzzled about the old behavior. |
|
I think we need to write some more tests for the |
|
😌 |
test/api/it.spec.js
Outdated
| describe('and the first expression is a function', () => { | ||
| it('fails with a diff including all items in the chain', () => { | ||
| expect( | ||
| function() { |
There was a problem hiding this comment.
Should be fine to use arrow functions here, as long as they're not part of the expected error message.
papandreou
left a comment
There was a problem hiding this comment.
Looks great, thanks so much for fixing it up! I can't approve because I originally opened the PR, but
!
|
I really like this. It is my firm belief that it cleans up a potentially confusing inconsistency and provides a very uniform story around how to go about comparing values. With the understanding that the |
alexjeffburke
left a comment
There was a problem hiding this comment.
I think it's a nice outcome that type check ends up being for expect.it specifically while shifted values gets dispatched the same way. Nice.
|
A final thought while looking at this - there may be other implementations of "to satisfy" that need to catch up with this. I think at least U-map (since it sadly had to duplicate quite a bit). I'd love to catch that in an automated way but it might be that test cases need to be added. What do you both think? |
|
@alexjeffburke, could be! Let's hope we have good test coverage in those plugins 👿 |
Should have been removed in #328
…hat should have been changed in #328
This PR changes to satisfy to stop calling functions on the RHS with the value on the LHS, this behavior was too surprising. To replicate the old behavior you would have to use
expect.it(v => ...)instead.Before:
(It is only in rare circumstances you need this functionality as you can usually just use a normal expect.it expression.
After:
We still support using a function in places where it is not confusing:
(This is also a rare case as you can write the same like this: