@@ -7,7 +7,8 @@ import * as rtl from 'react-testing-library'
7
7
import {
8
8
Provider as ProviderMock ,
9
9
useSelector ,
10
- shallowEqual
10
+ shallowEqual ,
11
+ connect
11
12
} from '../../src/index.js'
12
13
import { useReduxContext } from '../../src/hooks/useReduxContext'
13
14
@@ -333,6 +334,47 @@ describe('React', () => {
333
334
334
335
spy . mockRestore ( )
335
336
} )
337
+
338
+ it ( 'allows dealing with stale props by putting a specific connected component above the hooks component' , ( ) => {
339
+ const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
340
+
341
+ const Parent = ( ) => {
342
+ const count = useSelector ( s => s . count )
343
+ return < ConnectedWrapper parentCount = { count } />
344
+ }
345
+
346
+ const ConnectedWrapper = connect ( ( { count } ) => ( { count } ) ) (
347
+ ( { parentCount } ) => {
348
+ return < Child parentCount = { parentCount } />
349
+ }
350
+ )
351
+
352
+ let sawInconsistentState = false
353
+
354
+ const Child = ( { parentCount } ) => {
355
+ const result = useSelector ( ( { count } ) => {
356
+ if ( count !== parentCount ) {
357
+ sawInconsistentState = true
358
+ }
359
+
360
+ return count + parentCount
361
+ } )
362
+
363
+ return < div > { result } </ div >
364
+ }
365
+
366
+ rtl . render (
367
+ < ProviderMock store = { store } >
368
+ < Parent />
369
+ </ ProviderMock >
370
+ )
371
+
372
+ store . dispatch ( { type : '' } )
373
+
374
+ expect ( sawInconsistentState ) . toBe ( false )
375
+
376
+ spy . mockRestore ( )
377
+ } )
336
378
} )
337
379
338
380
describe ( 'error handling for invalid arguments' , ( ) => {
0 commit comments