6
如何使用Jest模拟同一模块中的函数
更新:我在https://github.com/magicmark/jest-how-do-i-mock-x/blob/master/src/function-in-same-module/README中收集了此方法和其他方法。 md 正确模拟以下示例的最佳方法是什么? 问题在于,导入时间过后,foo将原始引用保持不变bar。 module.js: export function bar () { return 'bar'; } export function foo () { return `I am foo. bar is ${bar()}`; } module.test.js: import * as module from '../src/module'; describe('module', () => { let barSpy; beforeEach(() => { barSpy = jest.spyOn( module, 'bar' ).mockImplementation(jest.fn()); }); afterEach(() …