Closed cmacdonnacha closed 4 years ago
Hi,
what it does for you that the built in Jest mocking doesn't?
In short? Nothing. This library uses Jest's mocking support as well, so everything this library does you can do by your own as well.
However, depending on your needs, there might be situations were using this library is advantageous to using your approach (which is also the approach outlined in the Jest docs).
Precisely, the control flow for "your" approach looks like this:
fetchMockPosts
) ("Arrange")render(<Page />)
) ("Act")Do assertions. (expect().toBe
) ("Assert")
This should work most of the time and follows the AAA-pattern.
This library is to / can be used in a slightly different flow:
This flow might help you with situations where you have multiple axios calls / the number of axios calls are unknown and where you want to response on-the-fly to calls instead of setting them up before hand. Apart from that, this library offers some convenience methods to respond to specific requests (getReqByMatchUrl
) instead of all / the first one as in mockResolvedValueOnce
(not saying you can't do this without this lib).
Hope this helps!
That's a great explanation @kingjan1999 thanks!
Hey,
I have been mocking my axios method via Jest for a while now but came across this package and I've wondered what it does for you that the built in Jest mocking doesn't?
In my React component I simply have: