Skip to content

Instantly share code, notes, and snippets.

@sliptype
Created June 14, 2019 16:12
Show Gist options
  • Save sliptype/b1ee5ba5774612e9ab8e946a1d6a2a36 to your computer and use it in GitHub Desktop.
Save sliptype/b1ee5ba5774612e9ab8e946a1d6a2a36 to your computer and use it in GitHub Desktop.
Testing React components using Redux Hooks with Jest
import { render, cleanup } from '@testing-library/react';
import { useSelector } from 'react-redux';
import { when } from 'jest-when';
import { getValue } from 'selectors';
jest.mock('react-redux');
afterEach(cleanup);
describe('Create Roll Job Modal', () => {
when(useSelector)
.calledWith(getValue)
.mockReturnValue(1);
it('Has value', async () => {
const { getByText } = render(<MyComponent />);
const rollButton = getByText('Roll Properties');
expect(getByText('1'));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment