jest.fn(() => 'something')
jest.fn().mockImplementation(() => 'something')
Is there any difference between these? bit confused.
CodePudding user response:
There is no difference. From the docs:
mockFn.mockImplementation(fn)
Accepts a function that should be used as the implementation of the mock. The mock itself will still record all calls that go into and instances that come from itself – the only difference is that the implementation will also be executed when the mock is called.
Note:
jest.fn(implementation)
is a shorthand forjest.fn().mockImplementation(implementation)
.