@@ -272,35 +272,80 @@ describe('Form.Validate', () => {
272272 expect ( form . getFieldError ( 'title' ) ) . toEqual ( [ 'Title should be 3+ characters' ] ) ;
273273 } ) ;
274274
275- it ( 'validate only accept exist fields' , async ( ) => {
276- let form ;
277- const onFinish = jest . fn ( ) ;
275+ describe ( 'validate only accept exist fields' , ( ) => {
276+ it ( 'skip init value' , async ( ) => {
277+ let form ;
278+ const onFinish = jest . fn ( ) ;
278279
279- const wrapper = mount (
280- < div >
280+ const wrapper = mount (
281+ < div >
282+ < Form
283+ onFinish = { onFinish }
284+ ref = { instance => {
285+ form = instance ;
286+ } }
287+ initialValues = { { user : 'light' , pass : 'bamboo' } }
288+ >
289+ < InfoField name = "user" >
290+ < Input />
291+ </ InfoField >
292+ < button type = "submit" > submit</ button >
293+ </ Form >
294+ </ div > ,
295+ ) ;
296+
297+ // Validate callback
298+ expect ( await form . validateFields ( [ 'user' ] ) ) . toEqual ( { user : 'light' } ) ;
299+ expect ( await form . validateFields ( ) ) . toEqual ( { user : 'light' } ) ;
300+
301+ // Submit callback
302+ wrapper . find ( 'button' ) . simulate ( 'submit' ) ;
303+ await timeout ( ) ;
304+ expect ( onFinish ) . toHaveBeenCalledWith ( { user : 'light' } ) ;
305+ } ) ;
306+
307+ it ( 'remove from fields' , async ( ) => {
308+ const onFinish = jest . fn ( ) ;
309+ const wrapper = mount (
281310 < Form
282311 onFinish = { onFinish }
283- ref = { instance => {
284- form = instance ;
312+ initialValues = { {
313+ switch : true ,
314+ ignore : 'test' ,
285315 } }
286- initialValues = { { user : 'light' , pass : 'bamboo' } }
287316 >
288- < InfoField name = "user " >
289- < Input />
317+ < InfoField name = "switch" valuePropName = "checked ">
318+ < Input type = "checkbox" className = "switch" />
290319 </ InfoField >
320+ < Field shouldUpdate >
321+ { ( _ , __ , { getFieldValue } ) =>
322+ getFieldValue ( 'switch' ) && (
323+ < InfoField name = "ignore" >
324+ < Input className = "ignore" />
325+ </ InfoField >
326+ )
327+ }
328+ </ Field >
291329 < button type = "submit" > submit</ button >
292- </ Form >
293- </ div > ,
294- ) ;
295-
296- // Validate callback
297- expect ( await form . validateFields ( [ 'user' ] ) ) . toEqual ( { user : 'light' } ) ;
298- expect ( await form . validateFields ( ) ) . toEqual ( { user : 'light' } ) ;
330+ </ Form > ,
331+ ) ;
299332
300- // Submit callback
301- wrapper . find ( 'button' ) . simulate ( 'submit' ) ;
302- await timeout ( ) ;
303- expect ( onFinish ) . toHaveBeenCalledWith ( { user : 'light' } ) ;
333+ // Submit callback
334+ wrapper . find ( 'button' ) . simulate ( 'submit' ) ;
335+ await timeout ( ) ;
336+ expect ( onFinish ) . toHaveBeenCalledWith ( { switch : true , ignore : 'test' } ) ;
337+ onFinish . mockReset ( ) ;
338+
339+ // Hide one
340+ wrapper . find ( 'input.switch' ) . simulate ( 'change' , {
341+ target : {
342+ checked : false ,
343+ } ,
344+ } ) ;
345+ wrapper . find ( 'button' ) . simulate ( 'submit' ) ;
346+ await timeout ( ) ;
347+ expect ( onFinish ) . toHaveBeenCalledWith ( { switch : false } ) ;
348+ } ) ;
304349 } ) ;
305350
306351 it ( 'should error in console if user script failed' , async ( ) => {
0 commit comments