首页 > 解决方案 > 通过索引文件导出的 Sinon 存根函数

问题描述

考虑以下打字稿文件:

export const funcA = ()=>{}
export const funcB = ()=>{}
export * from './A.ts'
export * from './B.ts'

现在在我的测试中,如果我直接导​​入内部文件,我可以模拟它的成员:

import * as A from './A.ts'
sinon.stub(A,'funcA');

但是,如果我导入索引,它不会让我模拟它的成员:

import * as myModule from `./index.ts`
sinon.stub(myModule,'funcA'); // does not work

有人可以解释吗?有不同的方法吗?

标签: typescriptsinon

解决方案


推荐阅读