How can I get the arguments called in jest mock function? I want to inspect the object that is passed as argument. Answer Just use mockObject.calls. In my case I used: Here’s the documentation about the mock property
Tag: jestjs
Components using Date objects produce different snapshots in different timezones
I’m using Enzyme with enzyme-to-json to do Jest snapshot testing of my React components. I’m testing shallow snapshots of a DateRange component that renders a display field with the current range (e.g. 5/20/2016 – 7/18/2016) and two DateInput components that allow selecting a Date value. This means that my snapshot contains the Dates I pass to the component both in
How can I exclude files from Jest watch?
I’m doing some slightly bizarre stuff using Jest for testing where I’m writing some stuff to disk. If I use the watch flag in Jest however then I’m finding (quite obviously) that each time I write something to disk the tests refire again. I don’t currently have any sort of configuration, and I’ve taken a look at the documentation, but
Mocking globals in Jest
Is there any way in Jest to mock global objects, such as navigator, or Image*? I’ve pretty much given up on this, and left it up to a series of mockable utility methods. For example: Testing this tiny function is simple, but crufty and not deterministic at all. I can get 75% of the way there, but this is about
How to check multiple arguments on multiple calls for jest spies?
I have the following function in a React component: This is my test that at least gets the spy to be called: However, the assertion is not working: What is the right way to use toHaveBeenCalledWith? Answer I was able mock multiple calls and check the arguments this way: where mockFn is your mocked function name.