Skip to content

Instantly share code, notes, and snippets.

@coryhouse
Created March 29, 2019 17:32
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 coryhouse/095a373a009606a84d58fd20af69d91f to your computer and use it in GitHub Desktop.
Save coryhouse/095a373a009606a84d58fd20af69d91f to your computer and use it in GitHub Desktop.
Custom centralized render for react-testing-library
import { render as r } from 'react-testing-library'
import { createStore } from 'redux'
import { Provider as ReduxProvider } from 'react-redux'
import { LocationProvider, createHistory } from "@reach/router"
import { AuthenicationProvider, createAuth } from '../auth'
import { reducer } from '../state'
export function reducer(ui, {
initialState = {},
store = createStore(reducer, initialState),
history = createHistory(),
auth = createAuth()
} = {}) {
const WrapperUI = () => (
<ReduxProvider store={store}>
<AuthenicationProvider auth={auth}>
<LocationProvider history={history}>{ui}</LocationProvider
</AuthenicationProvider>
</ReduxProvider>
)
return { ...r(<WrappedUI />), store, history }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment