question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Received calls check should deep-compare arguments

See original GitHub issue

First, 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:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ffMathycommented, Feb 14, 2020

I added you now! Enjoy full rights to the repo 😁

And thanks once again for helping many users of this library.

0reactions
notanengineercomcommented, Feb 14, 2020

Sure ^^ I am working on a few more contributions. Thanks for offering 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found