Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between jest.fn(implementationCallback) and jest.fn().mockImplementation(implementationCallback)

I've noticed we got the same behavior when we jest.fn() with the implementation passed as param in the .fn() and jest.fn().mockImplementation(). If so, choosing the fit is jut a matter of tastes?

Example:

jest.fn((num1, num2) => num1 + num2)
// same as 
jest.fn().mockImplementation((num1, num2) => num1 + num2)

Does anyone have some thoughts?

like image 333
Jhonatan Avatar asked Jun 17 '26 02:06

Jhonatan


1 Answers

jest.fn(implementation) is a shorthand for jest.fn().mockImplementation(implementation)

Not much to think about :)

like image 132
k-wasilewski Avatar answered Jun 19 '26 17:06

k-wasilewski