@@ -109,6 +109,32 @@ describe('React', () => {
109
109
expect ( div . props . string ) . toBe ( 'ab' ) ;
110
110
} ) ;
111
111
112
+ it ( 'should handle dispatches before componentDidMount' , ( ) => {
113
+ const store = createStore ( stringBuilder ) ;
114
+
115
+ @connect ( state => ( { string : state } ) )
116
+ class Container extends Component {
117
+ componentWillMount ( ) {
118
+ store . dispatch ( { type : 'APPEND' , body : 'a' } ) ;
119
+ }
120
+
121
+ render ( ) {
122
+ return < div { ...this . props } /> ;
123
+ }
124
+ }
125
+
126
+ const tree = TestUtils . renderIntoDocument (
127
+ < Provider store = { store } >
128
+ { ( ) => (
129
+ < Container />
130
+ ) }
131
+ </ Provider >
132
+ ) ;
133
+
134
+ const div = TestUtils . findRenderedDOMComponentWithTag ( tree , 'div' ) ;
135
+ expect ( div . props . string ) . toBe ( 'a' ) ;
136
+ } ) ;
137
+
112
138
it ( 'should handle additional prop changes in addition to slice' , ( ) => {
113
139
const store = createStore ( ( ) => ( {
114
140
foo : 'bar'
@@ -469,6 +495,18 @@ describe('React', () => {
469
495
}
470
496
}
471
497
498
+ @connect (
499
+ ( ) => ( { foo : 'bar' } ) ,
500
+ ( ) => ( { scooby : 'boo' } )
501
+ )
502
+ class ContainerNext extends Component {
503
+ render ( ) {
504
+ return (
505
+ < div { ...this . props } />
506
+ ) ;
507
+ }
508
+ }
509
+
472
510
let container ;
473
511
TestUtils . renderIntoDocument (
474
512
< Provider store = { store } >
@@ -479,18 +517,25 @@ describe('React', () => {
479
517
expect ( div . props . foo ) . toEqual ( undefined ) ;
480
518
expect ( div . props . scooby ) . toEqual ( 'doo' ) ;
481
519
482
- // Crude imitation of hot reloading that does the job
483
- Object . keys ( ContainerAfter . prototype ) . filter ( key =>
484
- typeof ContainerAfter . prototype [ key ] === 'function'
485
- ) . forEach ( key => {
486
- if ( key !== 'render' ) {
487
- ContainerBefore . prototype [ key ] = ContainerAfter . prototype [ key ] ;
488
- }
489
- } ) ;
520
+ function imitateHotReloading ( TargetClass , SourceClass ) {
521
+ // Crude imitation of hot reloading that does the job
522
+ Object . keys ( SourceClass . prototype ) . filter ( key =>
523
+ typeof SourceClass . prototype [ key ] === 'function'
524
+ ) . forEach ( key => {
525
+ if ( key !== 'render' ) {
526
+ TargetClass . prototype [ key ] = SourceClass . prototype [ key ] ;
527
+ }
528
+ } ) ;
529
+ container . forceUpdate ( ) ;
530
+ }
490
531
491
- container . forceUpdate ( ) ;
532
+ imitateHotReloading ( ContainerBefore , ContainerAfter ) ;
492
533
expect ( div . props . foo ) . toEqual ( 'baz' ) ;
493
534
expect ( div . props . scooby ) . toEqual ( 'foo' ) ;
535
+
536
+ imitateHotReloading ( ContainerBefore , ContainerNext ) ;
537
+ expect ( div . props . foo ) . toEqual ( 'bar' ) ;
538
+ expect ( div . props . scooby ) . toEqual ( 'boo' ) ;
494
539
} ) ;
495
540
496
541
it ( 'should set the displayName correctly' , ( ) => {
0 commit comments