I am writing the Unit test cases for my react project and using jest and enzyme for writing test cases. I have read the jest documentation
https://jestjs.io/docs/en/jest-object.html#jestspyonobject-methodname
which explains about jest.spyOn()
method but I didn't understand completely.
So I want to know more details about the specific places where we should use jest.fn()
and Where we should/must use jest.spyOn()
. It would be a great help if can be explained with an example for both methods.
Thanks
My simple understanding of these two functions in react/frontend projects is the following:
jest.fn()
jest.spyOn()
mockRestore()
(Good blog post: https://medium.com/@rickhanlonii/understanding-jest-mocks-f0046c68e53c)