我试图监视由另一个函数调用的函数,这两个函数都驻留在外部文件中并导入。
Funcs.spec.js:
import * as Funcs from './Funcs'
describe('funcA', () => {
it('calls funcB', () => {
jest.spyOn(Funcs, 'funcB')
Funcs.funcA()
expect(Funcs.funcB).toHaveBeenCalled()
}
}
Run Code Online (Sandbox Code Playgroud)
Funcs.js:
export const funcA = () => {
funcB()
}
export const funcB = () => {}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,间谍在 Funcs.js 的范围内不受尊重。我可以做什么来监视 funcB 以便我知道 funcA 调用了它?