diff --git a/src/__tests__/reduxReactRouter-test.js b/src/__tests__/reduxReactRouter-test.js index 1c4e3f3..92a1444 100644 --- a/src/__tests__/reduxReactRouter-test.js +++ b/src/__tests__/reduxReactRouter-test.js @@ -8,7 +8,7 @@ import { import { createStore, combineReducers } from 'redux'; import React from 'react'; -import { Route } from 'react-router'; +import { Route, Redirect } from 'react-router'; import createHistory from 'history/lib/createMemoryHistory'; import sinon from 'sinon'; @@ -162,6 +162,72 @@ describe('reduxRouter()', () => { expect(store.getState().router.location.pathname) .to.equal('/parent/child/123'); }); + + it('works with onEnter', () => { + const reducer = combineReducers({ + router: routerStateReducer + }); + + let store; + const history = createHistory(); + + reduxReactRouter({ + history, + getRoutes: s => { + store = s; + function requireAuth(nextState, redirectTo) { + if (!s.getState().user) { + redirectTo(null, '/login'); + } + } + return ( + + + + + + + ); + } + })(createStore)(reducer); + + store.dispatch(pushState(null, '/parent/child/123', { key: 'value' })); + expect(store.getState().router.location.pathname) + .to.equal('/login'); + }); + + it('works with onEnter and Redirect', () => { + const reducer = combineReducers({ + router: routerStateReducer + }); + + let store; + const history = createHistory(); + + reduxReactRouter({ + history, + getRoutes: s => { + store = s; + function notNeedAuth(nextState, redirectTo) { + if (s.getState().user) { + redirectTo(null, '/parent/child/123'); + } + } + return ( + + + + + + + + ); + } + })(createStore)(reducer, { user: 'test_user' }); + + expect(store.getState().router.location.pathname) + .to.equal('/login'); + }); }); describe('onEnter hook', () => {