Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Commit 925813b

Browse files
committed
Add test for unsubscribe function
1 parent 233a4ce commit 925813b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,33 @@ describe('syncReduxAndRouter', () => {
204204
() => syncReduxAndRouter(history, store, state => state.notRouting)
205205
).toNotThrow();
206206
});
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+
});
207236
});

0 commit comments

Comments
 (0)