@@ -151,6 +151,10 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
151
151
} ) ;
152
152
} ) ;
153
153
154
+ // To ensure that "Revert" and toggling actions work as expected in
155
+ // Redux DevTools we need a couple of tests for it. In these tests we
156
+ // rely directly on the DevTools, as they implement these actions as
157
+ // middleware, and we don't want to implement this ourselves.
154
158
describe ( 'devtools' , ( ) => {
155
159
let history , store , devToolsStore , unsubscribe ;
156
160
@@ -173,50 +177,58 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
173
177
} ) ;
174
178
175
179
it ( 'resets to the initial url' , ( ) => {
176
- let lastPath ;
180
+ let currentPath ;
177
181
const historyUnsubscribe = history . listen ( location => {
178
- lastPath = location . pathname ;
182
+ currentPath = location . pathname ;
179
183
} ) ;
180
184
181
185
history . pushState ( null , '/bar' ) ;
182
186
store . dispatch ( pushPath ( '/baz' ) ) ;
183
187
188
+ // By calling reset we expect DevTools to re-play the initial state
189
+ // and the history to update to the initial path
184
190
devToolsStore . dispatch ( ActionCreators . reset ( ) ) ;
185
191
186
192
expect ( store . getState ( ) . routing . path ) . toEqual ( '/foo' ) ;
187
- expect ( lastPath ) . toEqual ( '/foo' ) ;
193
+ expect ( currentPath ) . toEqual ( '/foo' ) ;
194
+
195
+ historyUnsubscribe ( ) ;
188
196
} ) ;
189
197
190
198
it ( 'handles toggle after store change' , ( ) => {
191
- let lastPath ;
199
+ let currentPath ;
192
200
const historyUnsubscribe = history . listen ( location => {
193
- lastPath = location . pathname ;
201
+ currentPath = location . pathname ;
194
202
} ) ;
195
203
196
- // action 2
204
+ // DevTools action # 2
197
205
history . pushState ( null , '/foo2' ) ;
198
- // action 3
206
+ // DevTools action # 3
199
207
history . pushState ( null , '/foo3' ) ;
200
208
209
+ // When we toggle an action, the devtools will revert the action
210
+ // and we therefore expect the history to update to the previous path
201
211
devToolsStore . dispatch ( ActionCreators . toggleAction ( 3 ) ) ;
202
- expect ( lastPath ) . toEqual ( '/foo2' ) ;
212
+ expect ( currentPath ) . toEqual ( '/foo2' ) ;
203
213
204
214
historyUnsubscribe ( ) ;
205
215
} ) ;
206
216
207
217
it ( 'handles toggle after store change' , ( ) => {
208
- let lastPath ;
218
+ let currentPath ;
209
219
const historyUnsubscribe = history . listen ( location => {
210
- lastPath = location . pathname ;
220
+ currentPath = location . pathname ;
211
221
} ) ;
212
222
213
- // action 2
223
+ // DevTools action # 2
214
224
store . dispatch ( pushPath ( '/foo2' ) ) ;
215
- // action 3
225
+ // DevTools action # 3
216
226
store . dispatch ( pushPath ( '/foo3' ) ) ;
217
227
228
+ // When we toggle an action, the devtools will revert the action
229
+ // and we therefore expect the history to update to the previous path
218
230
devToolsStore . dispatch ( ActionCreators . toggleAction ( 3 ) ) ;
219
- expect ( lastPath ) . toEqual ( '/foo2' ) ;
231
+ expect ( currentPath ) . toEqual ( '/foo2' ) ;
220
232
221
233
historyUnsubscribe ( ) ;
222
234
} ) ;
0 commit comments