Skip to content

Instantly share code, notes, and snippets.

@xiongemi
Last active January 11, 2021 22:39
Show Gist options
  • Select an option

  • Save xiongemi/b3a43d6754409a2a23704d5efa791925 to your computer and use it in GitHub Desktop.

Select an option

Save xiongemi/b3a43d6754409a2a23704d5efa791925 to your computer and use it in GitHub Desktop.
setup mock store for unit testing
import { render } from '@testing-library/react';
import React from 'react';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
const mockStore = configureStore([]);
describe('...', () => {
let store;
beforeEach(() => {
store = mockStore({<mock store state value>});
store.dispatch = jest.fn();
});
it('...', () => {
render(
<Provider store={store}>
<Component ...>
</Provider>
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment