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) {
114114 return merged ;
115115 }
116116
117+ getUnderlyingRef ( ) {
118+ return this . underlyingRef ;
119+ }
120+
117121 render ( ) {
118- return < DecoratedComponent { ...this . merge ( ) } /> ;
122+ return < DecoratedComponent ref = { component => ( this . underlyingRef = component ) } { ...this . merge ( ) } /> ;
119123 }
120124 } ;
121125 } ;
Original file line number Diff line number Diff line change @@ -514,5 +514,39 @@ describe('React', () => {
514514
515515 expect ( decorated . DecoratedComponent ) . toBe ( Container ) ;
516516 } ) ;
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+ } ) ;
517551 } ) ;
518552} ) ;
You can’t perform that action at this time.
0 commit comments