how to mock npm uniqid for react unit test when using Jest?

走远了吗. 提交于 2021-02-19 07:10:45

问题


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.


回答1:


You can mock it like this:

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,
}))


来源:https://stackoverflow.com/questions/44537755/how-to-mock-npm-uniqid-for-react-unit-test-when-using-jest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!