@@ -42,9 +42,7 @@ describe('Form.Basic', () => {
42
42
43
43
it ( 'use component' , ( ) => {
44
44
const MyComponent = ( { children } ) => < div > { children } </ div > ;
45
- const wrapper = mount (
46
- < Form component = { MyComponent } > { renderContent ( ) } </ Form > ,
47
- ) ;
45
+ const wrapper = mount ( < Form component = { MyComponent } > { renderContent ( ) } </ Form > ) ;
48
46
expect ( wrapper . find ( 'form' ) . length ) . toBe ( 0 ) ;
49
47
expect ( wrapper . find ( MyComponent ) . length ) . toBe ( 1 ) ;
50
48
expect ( wrapper . find ( 'input' ) . length ) . toBe ( 2 ) ;
@@ -111,11 +109,7 @@ describe('Form.Basic', () => {
111
109
form = instance ;
112
110
} }
113
111
>
114
- < Field
115
- name = "username"
116
- rules = { [ { required : true } ] }
117
- onReset = { onReset }
118
- >
112
+ < Field name = "username" rules = { [ { required : true } ] } onReset = { onReset } >
119
113
< Input />
120
114
</ Field >
121
115
</ Form >
@@ -137,9 +131,7 @@ describe('Form.Basic', () => {
137
131
138
132
await changeValue ( getField ( wrapper , 'username' ) , '' ) ;
139
133
expect ( form . getFieldValue ( 'username' ) ) . toEqual ( '' ) ;
140
- expect ( form . getFieldError ( 'username' ) ) . toEqual ( [
141
- "'username' is required" ,
142
- ] ) ;
134
+ expect ( form . getFieldError ( 'username' ) ) . toEqual ( [ "'username' is required" ] ) ;
143
135
expect ( form . isFieldTouched ( 'username' ) ) . toBeTruthy ( ) ;
144
136
145
137
expect ( onReset ) . not . toHaveBeenCalled ( ) ;
@@ -183,9 +175,7 @@ describe('Form.Basic', () => {
183
175
expect ( form . getFieldError ( 'username' ) ) . toEqual ( [ ] ) ;
184
176
expect ( form . isFieldTouched ( 'username' ) ) . toBeFalsy ( ) ;
185
177
expect ( form . getFieldValue ( 'password' ) ) . toEqual ( '' ) ;
186
- expect ( form . getFieldError ( 'password' ) ) . toEqual ( [
187
- "'password' is required" ,
188
- ] ) ;
178
+ expect ( form . getFieldError ( 'password' ) ) . toEqual ( [ "'password' is required" ] ) ;
189
179
expect ( form . isFieldTouched ( 'password' ) ) . toBeTruthy ( ) ;
190
180
} ) ;
191
181
} ) ;
@@ -337,13 +327,8 @@ describe('Form.Basic', () => {
337
327
) ;
338
328
339
329
await changeValue ( getField ( wrapper ) , 'Bamboo' ) ;
340
- expect ( onValuesChange ) . toHaveBeenCalledWith (
341
- { username : 'Bamboo' } ,
342
- { username : 'Bamboo' } ,
343
- ) ;
344
- expect ( onChange ) . toHaveBeenCalledWith (
345
- expect . objectContaining ( { target : { value : 'Bamboo' } } ) ,
346
- ) ;
330
+ expect ( onValuesChange ) . toHaveBeenCalledWith ( { username : 'Bamboo' } , { username : 'Bamboo' } ) ;
331
+ expect ( onChange ) . toHaveBeenCalledWith ( expect . objectContaining ( { target : { value : 'Bamboo' } } ) ) ;
347
332
} ) ;
348
333
349
334
it ( 'submit' , async ( ) => {
@@ -422,19 +407,29 @@ describe('Form.Basic', () => {
422
407
</ div > ,
423
408
) ;
424
409
425
- wrapper
426
- . find ( 'input[type="checkbox"]' )
427
- . simulate ( 'change' , { target : { checked : true } } ) ;
410
+ wrapper . find ( 'input[type="checkbox"]' ) . simulate ( 'change' , { target : { checked : true } } ) ;
428
411
await timeout ( ) ;
429
412
expect ( form . getFieldsValue ( ) ) . toEqual ( { check : true } ) ;
430
413
431
- wrapper
432
- . find ( 'input[type="checkbox"]' )
433
- . simulate ( 'change' , { target : { checked : false } } ) ;
414
+ wrapper . find ( 'input[type="checkbox"]' ) . simulate ( 'change' , { target : { checked : false } } ) ;
434
415
await timeout ( ) ;
435
416
expect ( form . getFieldsValue ( ) ) . toEqual ( { check : false } ) ;
436
417
} ) ;
437
418
419
+ it ( 'getValueProps' , async ( ) => {
420
+ const wrapper = mount (
421
+ < div >
422
+ < Form initialValues = { { test : 'bamboo' } } >
423
+ < Field name = "test" getValueProps = { val => ( { light : val } ) } >
424
+ < span className = "anything" />
425
+ </ Field >
426
+ </ Form >
427
+ </ div > ,
428
+ ) ;
429
+
430
+ expect ( wrapper . find ( '.anything' ) . props ( ) . light ) . toEqual ( 'bamboo' ) ;
431
+ } ) ;
432
+
438
433
it ( 'shouldUpdate' , async ( ) => {
439
434
let isAllTouched ;
440
435
let hasError ;
@@ -450,8 +445,7 @@ describe('Form.Basic', () => {
450
445
< Field shouldUpdate >
451
446
{ ( _ , __ , { getFieldsError, isFieldsTouched } ) => {
452
447
isAllTouched = isFieldsTouched ( true ) ;
453
- hasError = getFieldsError ( ) . filter ( ( { errors } ) => errors . length )
454
- . length ;
448
+ hasError = getFieldsError ( ) . filter ( ( { errors } ) => errors . length ) . length ;
455
449
456
450
return null ;
457
451
} }
@@ -528,9 +522,7 @@ describe('Form.Basic', () => {
528
522
triggerUpdate . mockReset ( ) ;
529
523
530
524
// Not trigger render
531
- formRef . current . setFields ( [
532
- { name : 'others' , value : 'no need to update' } ,
533
- ] ) ;
525
+ formRef . current . setFields ( [ { name : 'others' , value : 'no need to update' } ] ) ;
534
526
wrapper . update ( ) ;
535
527
expect ( triggerUpdate ) . not . toHaveBeenCalled ( ) ;
536
528
@@ -579,10 +571,7 @@ describe('Form.Basic', () => {
579
571
form = instance ;
580
572
} }
581
573
>
582
- < Field
583
- name = "normal"
584
- rules = { [ { validator : ( ) => new Promise ( ( ) => { } ) } ] }
585
- >
574
+ < Field name = "normal" rules = { [ { validator : ( ) => new Promise ( ( ) => { } ) } ] } >
586
575
{ ( control , meta ) => {
587
576
currentMeta = meta ;
588
577
return < Input { ...control } /> ;
@@ -684,25 +673,16 @@ describe('Form.Basic', () => {
684
673
685
674
expect (
686
675
form . getFieldsValue ( null , meta => {
687
- expect ( Object . keys ( meta ) ) . toEqual ( [
688
- 'touched' ,
689
- 'validating' ,
690
- 'errors' ,
691
- 'name' ,
692
- ] ) ;
676
+ expect ( Object . keys ( meta ) ) . toEqual ( [ 'touched' , 'validating' , 'errors' , 'name' ] ) ;
693
677
return false ;
694
678
} ) ,
695
679
) . toEqual ( { } ) ;
696
680
697
- expect ( form . getFieldsValue ( null , ( ) => true ) ) . toEqual (
698
- form . getFieldsValue ( ) ,
699
- ) ;
681
+ expect ( form . getFieldsValue ( null , ( ) => true ) ) . toEqual ( form . getFieldsValue ( ) ) ;
700
682
expect ( form . getFieldsValue ( null , meta => meta . touched ) ) . toEqual ( { } ) ;
701
683
702
684
await changeValue ( getField ( wrapper , 0 ) , 'Bamboo' ) ;
703
- expect ( form . getFieldsValue ( null , ( ) => true ) ) . toEqual (
704
- form . getFieldsValue ( ) ,
705
- ) ;
685
+ expect ( form . getFieldsValue ( null , ( ) => true ) ) . toEqual ( form . getFieldsValue ( ) ) ;
706
686
expect ( form . getFieldsValue ( null , meta => meta . touched ) ) . toEqual ( {
707
687
username : 'Bamboo' ,
708
688
} ) ;
0 commit comments