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

Commit b7f10aa

Browse files
committed
Better test coverage
1 parent 5e41803 commit b7f10aa

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

test/index.js

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ describe('routeReducer', () => {
7171
});
7272
});
7373

74+
it('respects replace', () => {
75+
expect(routeReducer(state, {
76+
type: UPDATE_PATH,
77+
path: '/bar',
78+
replace: true,
79+
avoidRouterUpdate: false
80+
})).toEqual({
81+
path: '/bar',
82+
replace: true,
83+
state: undefined,
84+
changeId: 2
85+
});
86+
});
87+
7488
it('respects `avoidRouterUpdate` flag', () => {
7589
expect(routeReducer(state, {
7690
type: UPDATE_PATH,
@@ -99,13 +113,21 @@ describe('syncReduxAndRouter', () => {
99113
expect(store.getState().routing.path).toEqual('/foo');
100114
expect(store.getState().routing.state).toEqual({ bar: 'baz' });
101115

116+
history.replaceState(null, '/bar');
117+
expect(store.getState().routing.path).toEqual('/bar');
118+
expect(store.getState().routing.state).toBe(null);
119+
102120
history.pushState(null, '/bar');
103121
expect(store.getState().routing.path).toEqual('/bar');
104122
expect(store.getState().routing.state).toBe(null);
105123

106124
history.pushState(null, '/bar?query=1');
107125
expect(store.getState().routing.path).toEqual('/bar?query=1');
108126

127+
history.replaceState({ bar: 'baz' }, '/bar?query=1');
128+
expect(store.getState().routing.path).toEqual('/bar?query=1');
129+
expect(store.getState().routing.state).toEqual({ bar: 'baz' });
130+
109131
history.pushState(null, '/bar?query=1#hash=2');
110132
expect(store.getState().routing.path).toEqual('/bar?query=1#hash=2');
111133
});
@@ -135,26 +157,34 @@ describe('syncReduxAndRouter', () => {
135157
state: { bar: 'baz' }
136158
});
137159

138-
store.dispatch(pushPath('/bar'));
160+
store.dispatch(replacePath('/bar', { bar: 'foo' }));
139161
expect(store.getState().routing).toEqual({
140162
path: '/bar',
141163
changeId: 4,
164+
replace: true,
165+
state: { bar: 'foo' }
166+
});
167+
168+
store.dispatch(pushPath('/bar'));
169+
expect(store.getState().routing).toEqual({
170+
path: '/bar',
171+
changeId: 5,
142172
replace: false,
143173
state: undefined
144174
});
145175

146176
store.dispatch(pushPath('/bar?query=1'));
147177
expect(store.getState().routing).toEqual({
148178
path: '/bar?query=1',
149-
changeId: 5,
179+
changeId: 6,
150180
replace: false,
151181
state: undefined
152182
});
153183

154184
store.dispatch(pushPath('/bar?query=1#hash=2'));
155185
expect(store.getState().routing).toEqual({
156186
path: '/bar?query=1#hash=2',
157-
changeId: 6,
187+
changeId: 7,
158188
replace: false,
159189
state: undefined
160190
});
@@ -184,6 +214,14 @@ describe('syncReduxAndRouter', () => {
184214
replace: false,
185215
state: undefined
186216
});
217+
218+
store.dispatch(replacePath('/foo'));
219+
expect(store.getState().routing).toEqual({
220+
path: '/foo',
221+
changeId: 4,
222+
replace: true,
223+
state: undefined
224+
});
187225
});
188226

189227
it('does not update the router for other state changes', () => {
@@ -246,6 +284,15 @@ describe('syncReduxAndRouter', () => {
246284
});
247285
store.dispatch(pushPath('/bar'));
248286
}
287+
else if(location.pathname === '/replace') {
288+
expect(store.getState().routing).toEqual({
289+
path: '/replace',
290+
changeId: 4,
291+
replace: false,
292+
state: { bar: 'baz' }
293+
});
294+
store.dispatch(replacePath('/baz', { foo: 'bar' }));
295+
}
249296
});
250297

251298
store.dispatch(pushPath('/foo'));
@@ -255,6 +302,14 @@ describe('syncReduxAndRouter', () => {
255302
replace: false,
256303
state: undefined
257304
});
305+
306+
store.dispatch(pushPath('/replace', { bar: 'baz' }));
307+
expect(store.getState().routing).toEqual({
308+
path: '/baz',
309+
changeId: 5,
310+
replace: true,
311+
state: { foo: 'bar' }
312+
});
258313
})
259314

260315
it('throws if "routing" key is missing with default selectRouteState', () => {

0 commit comments

Comments
 (0)