@@ -4,6 +4,7 @@ import Adapter from 'enzyme-adapter-react-16';
4
4
import assert from 'power-assert' ;
5
5
import Input from '../../src/input' ;
6
6
import Form from '../../src/form/index' ;
7
+ import Field from '../../src/field' ;
7
8
8
9
const FormItem = Form . Item ;
9
10
const Submit = Form . Submit ;
@@ -150,4 +151,35 @@ describe('Reset', () => {
150
151
wrapper . find ( 'button' ) . simulate ( 'click' ) ;
151
152
assert ( wrapper . find ( 'input#first' ) . prop ( 'value' ) === 'test' ) ;
152
153
} ) ;
154
+
155
+ it ( 'should support custom filed' , ( ) => {
156
+ class Demo extends React . Component {
157
+ field = new Field ( this , { forceUpdate : true } ) ;
158
+
159
+ render ( ) {
160
+ const { init, setValue, reset } = this . field ;
161
+
162
+ return ( < div >
163
+ < Input { ...init ( 'input' , { initValue : 'test' } ) } />
164
+ < Reset field = { this . field } onClick = { reset } > click</ Reset >
165
+ </ div > ) ;
166
+ }
167
+ }
168
+
169
+ const wrapper = mount ( < Demo /> ) ;
170
+
171
+ assert ( wrapper . find ( 'input' ) . prop ( 'value' ) === 'test' ) ;
172
+ wrapper . find ( 'button' ) . simulate ( 'click' ) ;
173
+ assert ( wrapper . find ( 'input' ) . prop ( 'value' ) === '' ) ;
174
+ } )
175
+
176
+ it ( 'should warn & callback if field not exist' , ( ) => {
177
+
178
+ let warnFlag = false ;
179
+
180
+ const wrapper = mount ( < Reset onClick = { ( ) => warnFlag = true } /> ) ;
181
+
182
+ wrapper . find ( 'button' ) . simulate ( 'click' ) ;
183
+ assert ( warnFlag ) ;
184
+ } )
153
185
} ) ;
0 commit comments