@@ -85,7 +85,7 @@ describe('React', () => {
85
85
) . toNotThrow ( ) ;
86
86
} ) ;
87
87
88
- it ( 'should subscribe to the store changes' , ( ) => {
88
+ it ( 'should subscribe class components to the store changes' , ( ) => {
89
89
const store = createStore ( stringBuilder ) ;
90
90
91
91
@connect ( state => ( { string : state } ) )
@@ -109,6 +109,32 @@ describe('React', () => {
109
109
expect ( stub . props . string ) . toBe ( 'ab' ) ;
110
110
} ) ;
111
111
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
+
112
138
it ( 'should handle dispatches before componentDidMount' , ( ) => {
113
139
const store = createStore ( stringBuilder ) ;
114
140
@@ -1084,6 +1110,30 @@ describe('React', () => {
1084
1110
) ;
1085
1111
} ) ;
1086
1112
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
+
1087
1137
it ( 'should return the instance of the wrapped component for use in calling child methods' , ( ) => {
1088
1138
const store = createStore ( ( ) => ( { } ) ) ;
1089
1139
@@ -1101,7 +1151,7 @@ describe('React', () => {
1101
1151
}
1102
1152
}
1103
1153
1104
- const decorator = connect ( state => state ) ;
1154
+ const decorator = connect ( state => state , null , null , { withRef : true } ) ;
1105
1155
const Decorated = decorator ( Container ) ;
1106
1156
1107
1157
const tree = TestUtils . renderIntoDocument (
@@ -1231,7 +1281,7 @@ describe('React', () => {
1231
1281
store . dispatch ( { type : 'APPEND' , body : 'a' } ) ;
1232
1282
let childMapStateInvokes = 0 ;
1233
1283
1234
- @connect ( state => ( { state } ) )
1284
+ @connect ( state => ( { state } ) , null , null , { withRef : true } )
1235
1285
class Container extends Component {
1236
1286
1237
1287
emitChange ( ) {
0 commit comments