我想测试一个React组件,组件的存储正在做一些gRPC通信,因此需要grpc node_module。我的测试是通过链接导入grpc,因为它导入了React组件,该组件导入了导入grpc的存储。Jest手动模拟不工作
这是好的,但automock失败: Error: The specified module could not be found. \\?\C:\Dev\Projects\Electron\PAT\client\app\node_modules\grpc\src\node\extension_binary\grpc_node.node
所以我把一个嘲笑文件夹相邻的每玩笑Documentation node_modules和它里面我创建grpc.js:
const grpc = {};
export default grpc;
这让我进一步,但: TypeError: grpc.makeGenericClientConstructor is not a function
可以理解,所以我尝试改变grpc.j s到是:
const grpc = { makeGenericClientConstructor:() => { return; } };
但我仍然得到同样的错误: TypeError: grpc.makeGenericClientConstructor is not a function
我使用jest.setMock和jest.mock试过,既不似乎帮助。
任何想法/建议/解决方法?
是否将其评估为ES6模块?如果不是使用'export default grpc',而是使用commonjs,会发生什么? 'module.exports = grpc;'? –
这个修复它谢谢你!你想回答这个问题吗? – austinrulezd00d