@@ -184,4 +184,53 @@ describe('syncReduxAndRouter', () => {
184
184
changeId : 3
185
185
} ) ;
186
186
} )
187
+
188
+ it ( 'throws if "routing" key is missing with default selectRouteState' , ( ) => {
189
+ const store = createStore ( combineReducers ( {
190
+ notRouting : routeReducer
191
+ } ) ) ;
192
+ const history = createHistory ( ) ;
193
+ expect (
194
+ ( ) => syncReduxAndRouter ( history , store )
195
+ ) . toThrow ( / C a n n o t s y n c r o u t e r : r o u t e s t a t e d o e s n o t e x i s t / ) ;
196
+ } ) ;
197
+
198
+ it ( 'accepts custom selectRouterState' , ( ) => {
199
+ const store = createStore ( combineReducers ( {
200
+ notRouting : routeReducer
201
+ } ) ) ;
202
+ const history = createHistory ( ) ;
203
+ syncReduxAndRouter ( history , store , state => state . notRouting )
204
+ history . pushState ( null , '/bar' ) ;
205
+ expect ( store . getState ( ) . notRouting . path ) . toEqual ( '/bar' ) ;
206
+ } ) ;
207
+
208
+ it ( 'returns unsubscribe to stop listening to history and store' , ( ) => {
209
+ const store = createStore ( combineReducers ( {
210
+ routing : routeReducer
211
+ } ) ) ;
212
+ const history = createHistory ( ) ;
213
+ const unsubscribe = syncReduxAndRouter ( history , store )
214
+
215
+ history . pushState ( null , '/foo' ) ;
216
+ expect ( store . getState ( ) . routing . path ) . toEqual ( '/foo' ) ;
217
+
218
+ store . dispatch ( updatePath ( '/bar' ) ) ;
219
+ expect ( store . getState ( ) . routing ) . toEqual ( {
220
+ path : '/bar' ,
221
+ changeId : 2
222
+ } ) ;
223
+
224
+ unsubscribe ( ) ;
225
+
226
+ history . pushState ( null , '/foo' ) ;
227
+ expect ( store . getState ( ) . routing . path ) . toEqual ( '/bar' ) ;
228
+
229
+ history . listenBefore ( location => {
230
+ throw new Error ( )
231
+ } ) ;
232
+ expect (
233
+ ( ) => store . dispatch ( updatePath ( '/foo' ) )
234
+ ) . toNotThrow ( ) ;
235
+ } ) ;
187
236
} ) ;
0 commit comments