- Published on
Using Jest toHaveBeenCalledWith() with expect.anything() to test a subset of parameters
Last week I had an interesting problem come across my desk. I was tasked with ensuring that when an onClick
handler was fired that a certain object was returned in the callback. Now this object would depend on the form state so I wanted to test several permutations. What was making things difficult was that the onClick callback returned a second object with many utility functions that were inherent to an underlying library and I wasn't interested in checking them as part of this testing.