Home > Mobile >  Jest: whats the diff between jest.fn() and jest.fn().mockImplementation() [duplicate]
Jest: whats the diff between jest.fn() and jest.fn().mockImplementation() [duplicate]

Time:09-23

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 for jest.fn().mockImplementation(implementation).

  • Related