@@ -178,7 +178,7 @@ describe('ConnectedRouter', () => {
178178 history . push ( '/new-location' )
179179 expect ( renderCount ) . toBe ( 2 )
180180 } )
181- } )
181+ } )
182182
183183 describe ( 'with immutable structure' , ( ) => {
184184 let ConnectedRouter
@@ -243,6 +243,62 @@ describe('ConnectedRouter', () => {
243243
244244 expect ( onLocationChangedSpy . mock . calls ) . toHaveLength ( 3 )
245245 } )
246+
247+ it ( 'only renders one time when mounted' , ( ) => {
248+ let renderCount = 0
249+
250+ const RenderCounter = ( ) => {
251+ renderCount ++
252+ return null
253+ }
254+
255+ mount (
256+ < Provider store = { store } >
257+ < ConnectedRouter { ...props } >
258+ < Route path = "/" component = { RenderCounter } />
259+ </ ConnectedRouter >
260+ </ Provider >
261+ )
262+
263+ expect ( renderCount ) . toBe ( 1 )
264+ } )
265+
266+ it ( 'does not render again when non-related action is fired' , ( ) => {
267+ // Initialize the render counter variable
268+ let renderCount = 0
269+
270+ // Create redux store with router state
271+ store = createStore (
272+ combineReducers ( {
273+ incrementReducer : ( state = 0 , action = { } ) => {
274+ if ( action . type === 'testAction' )
275+ return ++ state
276+
277+ return state
278+ } ,
279+ router : connectRouter ( history )
280+ } ) ,
281+ compose ( applyMiddleware ( routerMiddleware ( history ) ) )
282+ )
283+
284+
285+ const RenderCounter = ( ) => {
286+ renderCount ++
287+ return null
288+ }
289+
290+ mount (
291+ < Provider store = { store } >
292+ < ConnectedRouter { ...props } >
293+ < Route path = "/" component = { RenderCounter } />
294+ </ ConnectedRouter >
295+ </ Provider >
296+ )
297+
298+ store . dispatch ( { type : 'testAction' } )
299+ history . push ( '/new-location' )
300+ expect ( renderCount ) . toBe ( 2 )
301+ } )
246302 } )
247303
248304 describe ( 'with seamless immutable structure' , ( ) => {
@@ -290,6 +346,62 @@ describe('ConnectedRouter', () => {
290346
291347 expect ( onLocationChangedSpy . mock . calls ) . toHaveLength ( 2 )
292348 } )
349+
350+ it ( 'only renders one time when mounted' , ( ) => {
351+ let renderCount = 0
352+
353+ const RenderCounter = ( ) => {
354+ renderCount ++
355+ return null
356+ }
357+
358+ mount (
359+ < Provider store = { store } >
360+ < ConnectedRouter { ...props } >
361+ < Route path = "/" component = { RenderCounter } />
362+ </ ConnectedRouter >
363+ </ Provider >
364+ )
365+
366+ expect ( renderCount ) . toBe ( 1 )
367+ } )
368+
369+ it ( 'does not render again when non-related action is fired' , ( ) => {
370+ // Initialize the render counter variable
371+ let renderCount = 0
372+
373+ // Create redux store with router state
374+ store = createStore (
375+ combineReducers ( {
376+ incrementReducer : ( state = 0 , action = { } ) => {
377+ if ( action . type === 'testAction' )
378+ return ++ state
379+
380+ return state
381+ } ,
382+ router : connectRouter ( history )
383+ } ) ,
384+ compose ( applyMiddleware ( routerMiddleware ( history ) ) )
385+ )
386+
387+
388+ const RenderCounter = ( ) => {
389+ renderCount ++
390+ return null
391+ }
392+
393+ mount (
394+ < Provider store = { store } >
395+ < ConnectedRouter { ...props } >
396+ < Route path = "/" component = { RenderCounter } />
397+ </ ConnectedRouter >
398+ </ Provider >
399+ )
400+
401+ store . dispatch ( { type : 'testAction' } )
402+ history . push ( '/new-location' )
403+ expect ( renderCount ) . toBe ( 2 )
404+ } )
293405 } )
294406
295407 describe ( 'Redux DevTools' , ( ) => {
0 commit comments