相关疑难解决方法(0)

监视在 Jest 中调用另一个函数的导入函数

我试图监视由另一个函数调用的函数,这两个函数都驻留在外部文件中并导入。

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 调用了它?

ecmascript-6 jestjs

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

ecmascript-6 ×1

jestjs ×1