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

IT技术 reactjs jestjs babel-jest ts-jest
2021-05-22 23:02:21

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

例子:

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

有没有人有一些想法?

1个回答

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

没什么好考虑的:)