Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何模拟模块中的特定函数_Reactjs_Tdd_Jestjs_Enzyme - Fatal编程技术网

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的。