Created
March 29, 2019 17:32
-
-
Save coryhouse/095a373a009606a84d58fd20af69d91f to your computer and use it in GitHub Desktop.
Custom centralized render for react-testing-library
This file contains 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 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