DEV Community

Discussion on: Testing React Hook State Changes

Collapse
 
istvandesign profile image
Istvan Fulop • Edited

Hello,
Could you explain more exactly what does these do :

const setState = jest.fn();
const useStateSpy = jest.spyOn(React, 'useState')
useStateSpy.mockImplementation((init) => [init, setState]);

  1. How to set state with the mock implementation ?
  2. How to use with TypeScript ? What type should init have ?
  3. How to set multiple hooks set by useState ?
  4. How to mock a useState called by a promise ?