Last active
January 11, 2021 22:39
-
-
Save xiongemi/b3a43d6754409a2a23704d5efa791925 to your computer and use it in GitHub Desktop.
setup mock store for unit testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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