Skip to content

Instantly share code, notes, and snippets.

@Wellers0n
Created August 20, 2020 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wellers0n/b3ee3d458fa35a15bf0978f5a1b17d4a to your computer and use it in GitHub Desktop.
Save Wellers0n/b3ee3d458fa35a15bf0978f5a1b17d4a to your computer and use it in GitHub Desktop.
mock redux jest
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