Mock modules in Jest

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

Powered By Swish