Jhonatan
Jhonatan

Reputation: 1351

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?

Upvotes: 8

Views: 496

Answers (1)

k-wasilewski
k-wasilewski

Reputation: 4643

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

Not much to think about :)

Upvotes: 13

Related Questions