Reactjs 如何调试取消公告函数的Jest单元测试
我有以下功能:Reactjs 如何调试取消公告函数的Jest单元测试,reactjs,jestjs,lodash,webstorm,Reactjs,Jestjs,Lodash,Webstorm,我有以下功能: myFunction = _.debounce((viewport) => { ... otherFunction(); ... someOtherFunction(); ... }, 650) 我试图使用jest来断言otherFunction和someOtherFunction是否已运行。为了做到这一点,我想使用WebStorm的调试器来检查函数流 我试过模仿。.debounce: _.debounce = jest.fn((f
myFunction = _.debounce((viewport) => {
...
otherFunction();
...
someOtherFunction();
...
}, 650)
我试图使用jest来断言otherFunction
和someOtherFunction
是否已运行。为了做到这一点,我想使用WebStorm的调试器来检查函数流
我试过模仿。.debounce
:
_.debounce = jest.fn((fn) => fn);
即使我尝试在myFunction
上添加一个间谍,jest说该函数已运行,但我无法使调试器停止在函数内部
如果我尝试删除..debounce
函数,调试器将成功停止
有什么方法可以让它工作吗?这是未经测试的,但我相信您必须在模拟实现中执行该函数:
\uu.debounce=jest.fn(fn=>fn());
我最终将我的函数逻辑移动到了一个新函数:myfunctionnodebound
并且我只保留了旧的myFunction作为一个去盎司包装。这样,我就可以测试myfunctionnodebound
,而不需要测试myFunction
这当然不是最优雅的解决方案,但目前它仍然有效。我愿意接受更多的建议,以更好的方式解决这个问题
myFunctionNoDebounce = (viewport) => {
...
otherFunction();
...
someOtherFunction();
...
}
myFunction = _.debounce((viewport) => {
this.myFunctionNoDebounce(viewport)
}, 650)