File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -114,8 +114,12 @@ export default function createConnectDecorator(React) {
114
114
return merged ;
115
115
}
116
116
117
+ getUnderlyingRef ( ) {
118
+ return this . underlyingRef ;
119
+ }
120
+
117
121
render ( ) {
118
- return < DecoratedComponent { ...this . merge ( ) } /> ;
122
+ return < DecoratedComponent ref = { component => ( this . underlyingRef = component ) } { ...this . merge ( ) } /> ;
119
123
}
120
124
} ;
121
125
} ;
Original file line number Diff line number Diff line change @@ -514,5 +514,39 @@ describe('React', () => {
514
514
515
515
expect ( decorated . DecoratedComponent ) . toBe ( Container ) ;
516
516
} ) ;
517
+
518
+ it ( 'should return the instance of the wrapped component for use in calling child methods' , ( ) => {
519
+ const store = createStore ( ( ) => ( { } ) ) ;
520
+
521
+ const someData = {
522
+ some : 'data'
523
+ } ;
524
+
525
+ class Container extends Component {
526
+ someInstanceMethod ( ) {
527
+ return someData ;
528
+ }
529
+
530
+ render ( ) {
531
+ return < div /> ;
532
+ }
533
+ }
534
+
535
+ const decorator = connect ( state => state ) ;
536
+ const Decorated = decorator ( Container ) ;
537
+
538
+ const tree = TestUtils . renderIntoDocument (
539
+ < Provider store = { store } >
540
+ { ( ) => (
541
+ < Decorated />
542
+ ) }
543
+ </ Provider >
544
+ ) ;
545
+
546
+ const decorated = TestUtils . findRenderedComponentWithType ( tree , Decorated ) ;
547
+
548
+ expect ( ( ) => decorated . someInstanceMethod ( ) ) . toThrow ( ) ;
549
+ expect ( decorated . getUnderlyingRef ( ) . someInstanceMethod ( ) ) . toBe ( someData ) ;
550
+ } ) ;
517
551
} ) ;
518
552
} ) ;
You can’t perform that action at this time.
0 commit comments