title: Jest passing an object to expect().toBeCalledWith()
body: <p>I'm using jest to test my react components and I'm using <code>expect(...).toBeCalledWith(...);</code> to test if a function has been called with specific parameters, and it works fine with value types.</p>
  
  <p>The problem is I want to test a function that takes object as a parameter so when you call <code>expect(myFunc).toBeCalledWith(object);</code> the test always fails because of course the two object compared to each other do not have the same reference.</p>
  
  <p>so how can I solve this problem ?</p>
  
  <p>a sample code of what I'm trying to test is </p>
  
  <pre><code>it('the function should be called with the correct object', () =&gt; {
      api.submitForm = jest.fn().mockReturnValue(Promise.resolve());
      const wrapper = shallow(&lt;component /&gt;);
      const instance = wrapper.instance();
      instance.submitForm();
      const object = {
        foo : 'foo',
        bar: 'bar'
      };
      // this always fails even the function is called with the same object values
      expect(api.submitForm).toBeCalledWith(object);
    });
  </code></pre>
  
  <p>An error message would be something like this</p>
  
  <pre><code>Expected mock function to have been called with:
        [{"bar": "bar", "foo": "foo"}]
      But it was called with:
        [{"bar": "bar", "foo": "foo"}]
  </code></pre>
  
  <h2><strong>Update</strong></h2>
  
  <p>it seems the below code works fine</p>
  
  <pre><code>  expect(api.submitForm).toBeCalledWith(
      expect.objectContaining({
       foo : 'foo',
        bar: 'bar'
      }),
    );
  </code></pre>
  
  <p>however, if the object contains a property with array value, the above solution doesn't work</p>
  
  <pre><code>const obj = {
    foo : ['foo1', 'foo2'],
    bar: 'bar'
  }
  </code></pre>