Created
June 9, 2020 15:16
-
-
Save adngdb/2e7b8a18d3cb3582f8913e99ea3a12a3 to your computer and use it in GitHub Desktop.
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 { applyMiddleware, combineReducers, compose, createStore } from 'redux'; | |
import thunkMiddleware from 'redux-thunk'; | |
import { connectRouter, push, routerMiddleware } from 'connected-react-router'; | |
import { createBrowserHistory } from 'history'; | |
const history = createBrowserHistory({}); | |
const createRootReducer = (browserHistory) => combineReducers({ | |
router: connectRouter(browserHistory), | |
}); | |
export function createReduxStore(initialState = {}) { | |
return createStore( | |
createRootReducer(history), | |
initialState, | |
compose( | |
applyMiddleware( | |
routerMiddleware(history), | |
thunkMiddleware, | |
) | |
) | |
); | |
} | |
describe('router', () => { | |
it('gets the correct data in URL', () => { | |
const store = createReduxStore(); | |
expect(store.getState().router.location.pathname).toEqual('/'); | |
store.dispatch(push('/kg/firefox/resource/?string=42')); | |
// This fails, `pathname` is still "/" | |
expect(store.getState().router.location.pathname).toEqual('/kg/firefox/resource/'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment