Skip to content

Instantly share code, notes, and snippets.

@adngdb
Created June 9, 2020 15:16
Show Gist options
  • Save adngdb/2e7b8a18d3cb3582f8913e99ea3a12a3 to your computer and use it in GitHub Desktop.
Save adngdb/2e7b8a18d3cb3582f8913e99ea3a12a3 to your computer and use it in GitHub Desktop.
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