@@ -60,6 +60,19 @@ describe('React', () => {
60
60
: prev
61
61
}
62
62
63
+ function imitateHotReloading ( TargetClass , SourceClass , container ) {
64
+ // Crude imitation of hot reloading that does the job
65
+ Object . getOwnPropertyNames ( SourceClass . prototype ) . filter ( key =>
66
+ typeof SourceClass . prototype [ key ] === 'function'
67
+ ) . forEach ( key => {
68
+ if ( key !== 'render' && key !== 'constructor' ) {
69
+ TargetClass . prototype [ key ] = SourceClass . prototype [ key ]
70
+ }
71
+ } )
72
+
73
+ container . forceUpdate ( )
74
+ }
75
+
63
76
it ( 'should receive the store in the context' , ( ) => {
64
77
const store = createStore ( ( ) => ( { } ) )
65
78
@@ -1375,28 +1388,76 @@ describe('React', () => {
1375
1388
expect ( stub . props . foo ) . toEqual ( undefined )
1376
1389
expect ( stub . props . scooby ) . toEqual ( 'doo' )
1377
1390
1378
- function imitateHotReloading ( TargetClass , SourceClass ) {
1379
- // Crude imitation of hot reloading that does the job
1380
- Object . getOwnPropertyNames ( SourceClass . prototype ) . filter ( key =>
1381
- typeof SourceClass . prototype [ key ] === 'function'
1382
- ) . forEach ( key => {
1383
- if ( key !== 'render' && key !== 'constructor' ) {
1384
- TargetClass . prototype [ key ] = SourceClass . prototype [ key ]
1385
- }
1386
- } )
1387
-
1388
- container . forceUpdate ( )
1389
- }
1390
-
1391
- imitateHotReloading ( ContainerBefore , ContainerAfter )
1391
+ imitateHotReloading ( ContainerBefore , ContainerAfter , container )
1392
1392
expect ( stub . props . foo ) . toEqual ( 'baz' )
1393
1393
expect ( stub . props . scooby ) . toEqual ( 'foo' )
1394
1394
1395
- imitateHotReloading ( ContainerBefore , ContainerNext )
1395
+ imitateHotReloading ( ContainerBefore , ContainerNext , container )
1396
1396
expect ( stub . props . foo ) . toEqual ( 'bar' )
1397
1397
expect ( stub . props . scooby ) . toEqual ( 'boo' )
1398
1398
} )
1399
1399
1400
+ it ( 'should persist listeners through hot update' , ( ) => {
1401
+ const ACTION_TYPE = "ACTION"
1402
+ const store = createStore ( ( state = { actions : 0 } , action ) => {
1403
+ switch ( action . type ) {
1404
+ case ACTION_TYPE : {
1405
+ return {
1406
+ actions : state . actions + 1
1407
+ }
1408
+ }
1409
+ default :
1410
+ return state
1411
+ }
1412
+ } )
1413
+
1414
+ @connect (
1415
+ ( state ) => ( { actions : state . actions } )
1416
+ )
1417
+ class Child extends Component {
1418
+ render ( ) {
1419
+ return < Passthrough { ...this . props } />
1420
+ }
1421
+ }
1422
+
1423
+ @connect (
1424
+ ( ) => ( { scooby : 'doo' } )
1425
+ )
1426
+ class ParentBefore extends Component {
1427
+ render ( ) {
1428
+ return (
1429
+ < Child />
1430
+ )
1431
+ }
1432
+ }
1433
+
1434
+ @connect (
1435
+ ( ) => ( { scooby : 'boo' } )
1436
+ )
1437
+ class ParentAfter extends Component {
1438
+ render ( ) {
1439
+ return (
1440
+ < Child />
1441
+ )
1442
+ }
1443
+ }
1444
+
1445
+ let container
1446
+ TestUtils . renderIntoDocument (
1447
+ < ProviderMock store = { store } >
1448
+ < ParentBefore ref = { instance => container = instance } />
1449
+ </ ProviderMock >
1450
+ )
1451
+
1452
+ const stub = TestUtils . findRenderedComponentWithType ( container , Passthrough )
1453
+
1454
+ imitateHotReloading ( ParentBefore , ParentAfter , container )
1455
+
1456
+ store . dispatch ( { type : ACTION_TYPE } )
1457
+
1458
+ expect ( stub . props . actions ) . toEqual ( 1 )
1459
+ } )
1460
+
1400
1461
it ( 'should set the displayName correctly' , ( ) => {
1401
1462
expect ( connect ( state => state ) (
1402
1463
class Foo extends Component {
0 commit comments