how to mock npm uniqid for react unit test when using Jest?
问题 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