@@ -85,7 +85,7 @@ describe('React', () => {
8585 ) . toNotThrow ( ) ;
8686 } ) ;
8787
88- it ( 'should subscribe to the store changes' , ( ) => {
88+ it ( 'should subscribe class components to the store changes' , ( ) => {
8989 const store = createStore ( stringBuilder ) ;
9090
9191 @connect ( state => ( { string : state } ) )
@@ -109,6 +109,32 @@ describe('React', () => {
109109 expect ( stub . props . string ) . toBe ( 'ab' ) ;
110110 } ) ;
111111
112+ it ( 'should subscribe pure function components to the store changes' , ( ) => {
113+ const store = createStore ( stringBuilder ) ;
114+
115+ let Container = connect (
116+ state => ( { string : state } )
117+ ) ( function Container ( props ) {
118+ return < Passthrough { ...props } /> ;
119+ } ) ;
120+
121+ const spy = expect . spyOn ( console , 'error' ) ;
122+ const tree = TestUtils . renderIntoDocument (
123+ < ProviderMock store = { store } >
124+ < Container />
125+ </ ProviderMock >
126+ ) ;
127+ spy . destroy ( ) ;
128+ expect ( spy . calls . length ) . toBe ( 0 ) ;
129+
130+ const stub = TestUtils . findRenderedComponentWithType ( tree , Passthrough ) ;
131+ expect ( stub . props . string ) . toBe ( '' ) ;
132+ store . dispatch ( { type : 'APPEND' , body : 'a' } ) ;
133+ expect ( stub . props . string ) . toBe ( 'a' ) ;
134+ store . dispatch ( { type : 'APPEND' , body : 'b' } ) ;
135+ expect ( stub . props . string ) . toBe ( 'ab' ) ;
136+ } ) ;
137+
112138 it ( 'should handle dispatches before componentDidMount' , ( ) => {
113139 const store = createStore ( stringBuilder ) ;
114140
@@ -1084,6 +1110,30 @@ describe('React', () => {
10841110 ) ;
10851111 } ) ;
10861112
1113+ it ( 'should throw when trying to access the wrapped instance if withRef is not specified' , ( ) => {
1114+ const store = createStore ( ( ) => ( { } ) ) ;
1115+
1116+ class Container extends Component {
1117+ render ( ) {
1118+ return < Passthrough /> ;
1119+ }
1120+ }
1121+
1122+ const decorator = connect ( state => state ) ;
1123+ const Decorated = decorator ( Container ) ;
1124+
1125+ const tree = TestUtils . renderIntoDocument (
1126+ < ProviderMock store = { store } >
1127+ < Decorated />
1128+ </ ProviderMock >
1129+ ) ;
1130+
1131+ const decorated = TestUtils . findRenderedComponentWithType ( tree , Decorated ) ;
1132+ expect ( ( ) => decorated . getWrappedInstance ( ) ) . toThrow (
1133+ / T o a c c e s s t h e w r a p p e d i n s t a n c e , y o u n e e d t o s p e c i f y \{ w i t h R e f : t r u e \} a s t h e f o u r t h a r g u m e n t o f t h e c o n n e c t \( \) c a l l \. /
1134+ ) ;
1135+ } ) ;
1136+
10871137 it ( 'should return the instance of the wrapped component for use in calling child methods' , ( ) => {
10881138 const store = createStore ( ( ) => ( { } ) ) ;
10891139
@@ -1101,7 +1151,7 @@ describe('React', () => {
11011151 }
11021152 }
11031153
1104- const decorator = connect ( state => state ) ;
1154+ const decorator = connect ( state => state , null , null , { withRef : true } ) ;
11051155 const Decorated = decorator ( Container ) ;
11061156
11071157 const tree = TestUtils . renderIntoDocument (
@@ -1231,7 +1281,7 @@ describe('React', () => {
12311281 store . dispatch ( { type : 'APPEND' , body : 'a' } ) ;
12321282 let childMapStateInvokes = 0 ;
12331283
1234- @connect ( state => ( { state } ) )
1284+ @connect ( state => ( { state } ) , null , null , { withRef : true } )
12351285 class Container extends Component {
12361286
12371287 emitChange ( ) {
0 commit comments