@@ -151,6 +151,10 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
151151 } ) ;
152152 } ) ;
153153
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.
154158 describe ( 'devtools' , ( ) => {
155159 let history , store , devToolsStore , unsubscribe ;
156160
@@ -173,50 +177,58 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
173177 } ) ;
174178
175179 it ( 'resets to the initial url' , ( ) => {
176- let lastPath ;
180+ let currentPath ;
177181 const historyUnsubscribe = history . listen ( location => {
178- lastPath = location . pathname ;
182+ currentPath = location . pathname ;
179183 } ) ;
180184
181185 history . pushState ( null , '/bar' ) ;
182186 store . dispatch ( pushPath ( '/baz' ) ) ;
183187
188+ // By calling reset we expect DevTools to re-play the initial state
189+ // and the history to update to the initial path
184190 devToolsStore . dispatch ( ActionCreators . reset ( ) ) ;
185191
186192 expect ( store . getState ( ) . routing . path ) . toEqual ( '/foo' ) ;
187- expect ( lastPath ) . toEqual ( '/foo' ) ;
193+ expect ( currentPath ) . toEqual ( '/foo' ) ;
194+
195+ historyUnsubscribe ( ) ;
188196 } ) ;
189197
190198 it ( 'handles toggle after store change' , ( ) => {
191- let lastPath ;
199+ let currentPath ;
192200 const historyUnsubscribe = history . listen ( location => {
193- lastPath = location . pathname ;
201+ currentPath = location . pathname ;
194202 } ) ;
195203
196- // action 2
204+ // DevTools action # 2
197205 history . pushState ( null , '/foo2' ) ;
198- // action 3
206+ // DevTools action # 3
199207 history . pushState ( null , '/foo3' ) ;
200208
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
201211 devToolsStore . dispatch ( ActionCreators . toggleAction ( 3 ) ) ;
202- expect ( lastPath ) . toEqual ( '/foo2' ) ;
212+ expect ( currentPath ) . toEqual ( '/foo2' ) ;
203213
204214 historyUnsubscribe ( ) ;
205215 } ) ;
206216
207217 it ( 'handles toggle after store change' , ( ) => {
208- let lastPath ;
218+ let currentPath ;
209219 const historyUnsubscribe = history . listen ( location => {
210- lastPath = location . pathname ;
220+ currentPath = location . pathname ;
211221 } ) ;
212222
213- // action 2
223+ // DevTools action # 2
214224 store . dispatch ( pushPath ( '/foo2' ) ) ;
215- // action 3
225+ // DevTools action # 3
216226 store . dispatch ( pushPath ( '/foo3' ) ) ;
217227
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
218230 devToolsStore . dispatch ( ActionCreators . toggleAction ( 3 ) ) ;
219- expect ( lastPath ) . toEqual ( '/foo2' ) ;
231+ expect ( currentPath ) . toEqual ( '/foo2' ) ;
220232
221233 historyUnsubscribe ( ) ;
222234 } ) ;
0 commit comments