Reactjs 如何模拟模块中的特定函数
假设我在Reactjs 如何模拟模块中的特定函数,reactjs,tdd,jestjs,enzyme,Reactjs,Tdd,Jestjs,Enzyme,假设我在module.js中有一个方法bestFunction: //module.js export const bestFunction=x=>{ 返回x+1 } 如果我的代码本身正在导入,我如何模拟bestFunction: 从'./module.js'导入{bestFunction} 在您的测试中: import*as依赖于“/module.js”; 描述(“测试时…”,()=>{ 在每个之前(()=>{ dependens.bestFunction=jest.fn().mockImp
module.js
中有一个方法bestFunction
:
//module.js
export const bestFunction=x=>{
返回x+1
}
如果我的代码本身正在导入,我如何模拟bestFunction
:
从'./module.js'导入{bestFunction}
在您的测试中:
import*as依赖于“/module.js”;
描述(“测试时…”,()=>{
在每个之前(()=>{
dependens.bestFunction=jest.fn().mockImplementation(()=>22);
})
它('doStuff',()=>{
expect(objectUnderTest.foo()).toEqual('22个红气球');
});
});
这篇文章很让人困惑,因为标题上写的是un mock,但问题是关于mock的。