@@ -71,6 +71,20 @@ describe('routeReducer', () => {
71
71
} ) ;
72
72
} ) ;
73
73
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
+
74
88
it ( 'respects `avoidRouterUpdate` flag' , ( ) => {
75
89
expect ( routeReducer ( state , {
76
90
type : UPDATE_PATH ,
@@ -99,13 +113,21 @@ describe('syncReduxAndRouter', () => {
99
113
expect ( store . getState ( ) . routing . path ) . toEqual ( '/foo' ) ;
100
114
expect ( store . getState ( ) . routing . state ) . toEqual ( { bar : 'baz' } ) ;
101
115
116
+ history . replaceState ( null , '/bar' ) ;
117
+ expect ( store . getState ( ) . routing . path ) . toEqual ( '/bar' ) ;
118
+ expect ( store . getState ( ) . routing . state ) . toBe ( null ) ;
119
+
102
120
history . pushState ( null , '/bar' ) ;
103
121
expect ( store . getState ( ) . routing . path ) . toEqual ( '/bar' ) ;
104
122
expect ( store . getState ( ) . routing . state ) . toBe ( null ) ;
105
123
106
124
history . pushState ( null , '/bar?query=1' ) ;
107
125
expect ( store . getState ( ) . routing . path ) . toEqual ( '/bar?query=1' ) ;
108
126
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
+
109
131
history . pushState ( null , '/bar?query=1#hash=2' ) ;
110
132
expect ( store . getState ( ) . routing . path ) . toEqual ( '/bar?query=1#hash=2' ) ;
111
133
} ) ;
@@ -135,26 +157,34 @@ describe('syncReduxAndRouter', () => {
135
157
state : { bar : 'baz' }
136
158
} ) ;
137
159
138
- store . dispatch ( pushPath ( '/bar' ) ) ;
160
+ store . dispatch ( replacePath ( '/bar' , { bar : 'foo' } ) ) ;
139
161
expect ( store . getState ( ) . routing ) . toEqual ( {
140
162
path : '/bar' ,
141
163
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 ,
142
172
replace : false ,
143
173
state : undefined
144
174
} ) ;
145
175
146
176
store . dispatch ( pushPath ( '/bar?query=1' ) ) ;
147
177
expect ( store . getState ( ) . routing ) . toEqual ( {
148
178
path : '/bar?query=1' ,
149
- changeId : 5 ,
179
+ changeId : 6 ,
150
180
replace : false ,
151
181
state : undefined
152
182
} ) ;
153
183
154
184
store . dispatch ( pushPath ( '/bar?query=1#hash=2' ) ) ;
155
185
expect ( store . getState ( ) . routing ) . toEqual ( {
156
186
path : '/bar?query=1#hash=2' ,
157
- changeId : 6 ,
187
+ changeId : 7 ,
158
188
replace : false ,
159
189
state : undefined
160
190
} ) ;
@@ -184,6 +214,14 @@ describe('syncReduxAndRouter', () => {
184
214
replace : false ,
185
215
state : undefined
186
216
} ) ;
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
+ } ) ;
187
225
} ) ;
188
226
189
227
it ( 'does not update the router for other state changes' , ( ) => {
@@ -246,6 +284,15 @@ describe('syncReduxAndRouter', () => {
246
284
} ) ;
247
285
store . dispatch ( pushPath ( '/bar' ) ) ;
248
286
}
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
+ }
249
296
} ) ;
250
297
251
298
store . dispatch ( pushPath ( '/foo' ) ) ;
@@ -255,6 +302,14 @@ describe('syncReduxAndRouter', () => {
255
302
replace : false ,
256
303
state : undefined
257
304
} ) ;
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
+ } ) ;
258
313
} )
259
314
260
315
it ( 'throws if "routing" key is missing with default selectRouteState' , ( ) => {
0 commit comments