Created
August 20, 2020 17:21
-
-
Save Wellers0n/b3ee3d458fa35a15bf0978f5a1b17d4a to your computer and use it in GitHub Desktop.
mock redux jest
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 React from 'react' | |
import { render } from '@testing-library/react' | |
import { createStore } from 'redux' | |
import { Provider } from 'react-redux' | |
import reducers from 'your-reducers' | |
function renderWithRedux( | |
ui, | |
{ initialState, store = createStore(reducers, initialState) } = {} | |
) { | |
return { | |
...render(<Provider store={store}>{ui}</Provider>), | |
// adding `store` to the returned utilities to allow us | |
// to reference it in our tests (just try to avoid using | |
// this to test implementation details). | |
store | |
} | |
} | |
function setup() { | |
const rendered = renderWithRedux(<YourComponent />) | |
return { ...rendered } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment