Mock modules in Jest
Wednesday, June 01, 2022
This is a valid way to mock modules in React codebases
jest.mock('react', () => ({
...jest.requireActual('react'),
useRef: jest.fn(),
}));
This example mocks the useRef function in the react module. This can be done for any type of module; imported from an npm package, a relative file path, etc
OTHER POSTS
Powered By Swish