我想測試一個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