Received calls check should deep-compare arguments
See original GitHub issueFirst, thanks for this amazing library!
I have being facing some issues when testing APIs that receive objects as arguments. Seems like the received call checks does not deep compare objects. Check out the example bellow:
it("it should get the correct object", async () => {
const obj = {
action: (value: { prop: string }) => `wow ${value.prop}`
};
const objMock = Substitute.for<typeof obj>();
const arg = { prop: "wow" };
objMock.action(arg);
// This test passes
objMock.received().action(arg);
/* This fails with:
Expected 1 or more calls to the method action2 with arguments [{ prop: 'wow' }], but received none of such calls.
All calls received to method action2:
-> call with arguments [{ prop: 'wow' }]
*/
objMock.received().action({ prop: "wow" });
});
I believe a possible solutions would be the library to offer a way to deep-compare the arguments. Another solution would be a method to have access to the list of calls and arguments, so we can compare the arguments using for example Jest expect.
I am open for thoughts and suggestions.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Allow Arg.Is to take a comparer and provide some useful ...
I've just started using NSubstitute and quickly ran into a problem when my method expected a collection argument, as described here: ...
Read more >Jest passing an object to expect().toBeCalledWith()
The problem is I want to test a function that takes object as a parameter so when you call expect(myFunc).toBeCalledWith(object); the test ......
Read more >JavaScript: Deep Comparison of Objects with a Recursive Call
After we are certain that both arguments are object , we will check if they have the same properties and values. Comparing the...
Read more >Argument matchers - NSubstitute
Argument matchers can be used when setting return values and when checking received calls. They provide a way to specify a call or...
Read more >A Complete Guide to Testing React Hooks - Toptal
This article explores how to test React Hooks and outlines an eight-step testing plan you could employ to test your own projects.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I added you now! Enjoy full rights to the repo 😁
And thanks once again for helping many users of this library.
Sure ^^ I am working on a few more contributions. Thanks for offering 😄