Skip to content

Instantly share code, notes, and snippets.

@marco-souza
Last active January 14, 2020 23:44
Show Gist options
  • Save marco-souza/ac413052ec18dc75f16a447193c511a4 to your computer and use it in GitHub Desktop.
Save marco-souza/ac413052ec18dc75f16a447193c511a4 to your computer and use it in GitHub Desktop.
mock a react hook
import { useLoadingMocked } from 'assets/__mocks__/useLoading';
// mock module as a function
jest.mock('src/redux/loading', () => jest.fn());
import methodToMock from 'src/redux/loading';
const mockedMethod = methodToMock as jest.Mock;
describe('testing a hook', () => {
it('my test', () => {
const mockObject = useLoadingMocked();
mockedMethod.mockImplementation(() => mockObject);
// ...
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment