[英]How to use Mock Functions in React JS using Jest?
我正在尝试使用以下功能模拟功能: Facebook的Jest Mock Functions
但是,我收到此错误:
jest.mock is not a function
TypeError: jest.mock is not a function
at evaluate (https://oq7kwzrnj5.codesandbox.io/src/ListItem.spec.js:21:6)
at r.a (https://codesandbox.io/static/js/sandbox.f3fc5e5b.js:5354:971)
at e.value (https://codesandbox.io/static/js/sandbox.f3fc5e5b.js:5413:270)
at e.value (https://codesandbox.io/static/js/sandbox.f3fc5e5b.js:5386:23195)
at e.value (https://codesandbox.io/static/js/sandbox.f3fc5e5b.js:5386:22974)
at e. (https://codesandbox.io/static/js/sandbox.f3fc5e5b.js:5386:18687)
at n (https://codesandbox.io/static/js/common-sandbox.5c75aa32.js:2847:811)
at Generator._invoke (https://codesandbox.io/static/js/common-sandbox.5c75aa32.js:2847:599)
at Generator.e.(anonymous function) [as next] (https://codesandbox.io/static/js/common-sandbox.5c75aa32.js:2847:990)
at o (https://codesandbox.io/static/js/common-sandbox.5c75aa32.js:3049:316)
at https://codesandbox.io/static/js/common-sandbox.5c75aa32.js:3049:464
at new Promise ()
at new t (https://codesandbox.io/static/js/common-sandbox.5c75aa32.js:678:776)
at https://codesandbox.io/static/js/common-sandbox.5c75aa32.js:3049:258
at https://codesandbox.io/static/js/sandbox.f3fc5e5b.js:5386:18996
at Array.map ()
这是我的代码: https : //codesandbox.io/s/oq7kwzrnj5
有人可以帮我解决这个错误吗?
任何更新
您可以像这样模拟函数mockMyFunc = jest.fn()
还要检查我对这个问题的答案: 为什么React JS中的实际长度和预期长度不相等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.