本文介绍了使用Jest时如何模拟npm uniqid进行反应单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试模拟npm uniqid库以进行反应单元测试.我已将此uniqid用于复选框.这用于组件渲染测试.
I'm trying to mock npm uniqid library for react unit test. I have used this uniqid for check box. This is for component render test.
推荐答案
您可以像这样模拟它:
jest.mock('uniqid', ()=>(i)=> i + 'someUniqId')
或者如果您使用其他功能之一
or if you use one of the other functions
jest.mock('uniqid', () = > ({
process: (i) => i + 'someProcess,
time: (i) => i + ' someTime,
}))
这篇关于使用Jest时如何模拟npm uniqid进行反应单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!