-
-
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
Allow deepEqual to use a custom comparator #1520
Comments
I had a quick look at the code, and unless I'm mistaken, that doesn't seem horribly hard to do (but I only looked very quickly tbh), at least for the simple expect and assert syntax (which to be frank is all that matters to me, I hate.expect.syntax.with.a.passion but from my understanding of the code, the easiest is to implement it for both interfaces anyway) |
One step further (or maybe it'd be the first step as it doesn't involve changing the API) could be to be able to change the default comparator
which would be even more useful |
Hey @forty; I'm not sure if we're able to land this in 5.0 but I think we can do this in a way that it's not a breaking change so it could be done in a minor version after 5.0. A pull request with this feature would help tremendously but otherwise it's just a matter of time until someone has the time to pick this up to work on. |
@koddsson thank you for you answer. I just pushed a MR to implement this on the 5.x.x branch. Thanks in advance for your feedback. |
I think we can close this now that the linked PR is merged? Feel free to re-open if not. |
This seems useful but the docs don't mention this functionality. Is that being considered in a separate PR ? |
deep-eql, the underlying library doing deep equality supports passing a custom comparator https://github.com/chaijs/deep-eql/blob/main/index.js#L87
Exposing it in chai would be super useful. This idea has been mentioned in several comments (especially on issue about loose equality, which is one use case for it) for example #644 (comment) (2016) but I did not find a proper ticket for it.
Syntax:
Example use case: interval
(ugly example to make it clear how that would work, but it'd certainly be more elegant with an IntervalComparison class for example which would work the same)
The text was updated successfully, but these errors were encountered: