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

Commit 2a65890

Browse files
committed
Add test that checks store updates
1 parent 3581f20 commit 2a65890

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/index.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,67 @@ describe('syncReduxAndRouter', () => {
273273
});
274274
});
275275

276+
it('does not unnecessarily update the store', () => {
277+
const { history, store } = createSyncedHistoryAndStore();
278+
const updates = [];
279+
280+
const unsubscribe = store.subscribe(() => {
281+
updates.push(store.getState())
282+
});
283+
284+
store.dispatch(pushPath('/foo'));
285+
store.dispatch(pushPath('/foo'));
286+
store.dispatch(pushPath('/foo', { bar: 'baz' }));
287+
store.dispatch(replacePath('/bar'));
288+
store.dispatch(replacePath('/bar', { bar: 'foo' }));
289+
290+
unsubscribe();
291+
292+
expect(updates.length).toBe(5);
293+
expect(updates).toEqual([
294+
{
295+
routing: {
296+
changeId: 2,
297+
path: '/foo',
298+
state: undefined,
299+
replace: false
300+
}
301+
},
302+
{
303+
routing: {
304+
changeId: 3,
305+
path: '/foo',
306+
state: undefined,
307+
replace: false
308+
}
309+
},
310+
{
311+
routing: {
312+
changeId: 4,
313+
path: '/foo',
314+
state: { bar: 'baz' },
315+
replace: false
316+
}
317+
},
318+
{
319+
routing: {
320+
changeId: 5,
321+
path: '/bar',
322+
state: undefined,
323+
replace: true
324+
}
325+
},
326+
{
327+
routing: {
328+
changeId: 6,
329+
path: '/bar',
330+
state: { bar: 'foo' },
331+
replace: true
332+
}
333+
}
334+
]);
335+
});
336+
276337
it('allows updating the route from within `listenBefore`', () => {
277338
const { history, store } = createSyncedHistoryAndStore();
278339
expect(store.getState().routing).toEqual({

0 commit comments

Comments
 (0)