jest.fn(implementationCallback) 和 jest.fn().mockImplementation(implementationCallback) 之间的区别

Jho*_*tan 7 reactjs jestjs babel-jest ts-jest

我注意到当我们 jest.fn() 并将实现作为 .fn() 和 jest.fn().mockImplementation() 中的参数传递时,我们得到了相同的行为。如果是这样,选择合适只是一个品味问题吗?

例子:

jest.fn((num1, num2) => num1 + num2)
// same as 
jest.fn().mockImplementation((num1, num2) => num1 + num2)
Run Code Online (Sandbox Code Playgroud)

有人有一些想法吗?

k-w*_*ski 13

jest.fn(implementation)是一个简写jest.fn().mockImplementation(implementation)

不用考虑太多:)