-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Partial matching for mock assertions #2137
Comments
Have you tried using asymmetric matchers? They are exposed through |
Worth noting they're available since Jest 18. |
Disregard my previous comments. Nevertheless I'm not convinced we need another type of matchers, because it's all possible through asymmetric matchers (now ported to Jest) without much more typing. e.g. you can use expect(mock).toHaveBeenCalledWith(expect.objectContaining({
two: expect.any(Number)
})); |
yep, agree with @thymikee here. |
Thanks @thymikee! This solved my problem! 😄 |
@andyearnshaw your example is the first thing which came to my mind when I read the solution provided by @thymikee. I currently have an object which I expect to be passed to my mocked method. It's not the same instance, though. It just represents the same value and has the same internal state. A method like |
You can add custom asymmetric matchers today ( |
@thymikee you just saved me after countless hours of coding. Thanks. Your solution worked for me. |
@thymikee You made my day |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
Asserting on parts of calls to mocks requires inspecting arguments or using a jasmine API
What is the expected behavior?
Asserting on parts of calls to mocks has a first-class API
Related - #1843
Currently, asserting that a mock was called with a complex object is less than ideal because you have to either supply the entire matching object, use jasmine.objectContaining, or inspect the calls yourself with
.mock.calls[x][y]
. I'd like to propose an API like the following.Ideally we could go even further and add some meta-matchers to the jest object (inspired by sinon's matchers) to unlock some powerful assertions.
The text was updated successfully, but these errors were encountered: