@@ -6,7 +6,7 @@ import Form, { Field, useForm } from '../src';
6
6
import { changeValue , getInput , matchError } from './common' ;
7
7
import InfoField , { Input } from './common/InfoField' ;
8
8
import timeout from './common/timeout' ;
9
- import type { Meta } from '@/interface' ;
9
+ import type { FormRef , Meta } from '@/interface' ;
10
10
11
11
describe ( 'Form.Basic' , ( ) => {
12
12
describe ( 'create form' , ( ) => {
@@ -85,7 +85,7 @@ describe('Form.Basic', () => {
85
85
} ) ;
86
86
87
87
it ( 'fields touched' , async ( ) => {
88
- const form = React . createRef < FormInstance > ( ) ;
88
+ const form = React . createRef < FormRef > ( ) ;
89
89
90
90
const { container } = render (
91
91
< div >
@@ -111,12 +111,15 @@ describe('Form.Basic', () => {
111
111
expect ( form . current ?. isFieldsTouched ( [ 'username' , 'password' ] ) ) . toBeTruthy ( ) ;
112
112
expect ( form . current ?. isFieldsTouched ( true ) ) . toBeTruthy ( ) ;
113
113
expect ( form . current ?. isFieldsTouched ( [ 'username' , 'password' ] , true ) ) . toBeTruthy ( ) ;
114
+
115
+ // nativeElementRef
116
+ expect ( form . current ?. nativeElement ) . toBeTruthy ( ) ;
114
117
} ) ;
115
118
116
119
describe ( 'reset form' , ( ) => {
117
120
function resetTest ( name : string , ...args ) {
118
121
it ( name , async ( ) => {
119
- const form = React . createRef < FormInstance > ( ) ;
122
+ const form = React . createRef < FormRef > ( ) ;
120
123
const onReset = jest . fn ( ) ;
121
124
const onMeta = jest . fn ( ) ;
122
125
@@ -187,7 +190,7 @@ describe('Form.Basic', () => {
187
190
resetTest ( 'without field name' ) ;
188
191
189
192
it ( 'not affect others' , async ( ) => {
190
- const form = React . createRef < FormInstance > ( ) ;
193
+ const form = React . createRef < FormRef > ( ) ;
191
194
192
195
const { container } = render (
193
196
< div >
@@ -345,7 +348,7 @@ describe('Form.Basic', () => {
345
348
it ( 'getInternalHooks should not usable by user' , ( ) => {
346
349
const errorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
347
350
348
- const form = React . createRef < FormInstance > ( ) ;
351
+ const form = React . createRef < FormRef > ( ) ;
349
352
render (
350
353
< div >
351
354
< Form ref = { form } />
@@ -362,7 +365,7 @@ describe('Form.Basic', () => {
362
365
} ) ;
363
366
364
367
it ( 'valuePropName' , async ( ) => {
365
- const form = React . createRef < FormInstance > ( ) ;
368
+ const form = React . createRef < FormRef > ( ) ;
366
369
const { container } = render (
367
370
< div >
368
371
< Form ref = { form } >
@@ -422,9 +425,7 @@ describe('Form.Basic', () => {
422
425
< Field getValueProps = { getValueProps1 } >
423
426
< span className = "anything" />
424
427
</ Field >
425
- < Field getValueProps = { getValueProps2 } >
426
- { ( ) => < span className = "anything" /> }
427
- </ Field >
428
+ < Field getValueProps = { getValueProps2 } > { ( ) => < span className = "anything" /> } </ Field >
428
429
</ Form >
429
430
</ div > ,
430
431
) ;
@@ -511,7 +512,7 @@ describe('Form.Basic', () => {
511
512
512
513
describe ( 'setFields' , ( ) => {
513
514
it ( 'should work' , ( ) => {
514
- const form = React . createRef < FormInstance > ( ) ;
515
+ const form = React . createRef < FormRef > ( ) ;
515
516
const { container } = render (
516
517
< div >
517
518
< Form ref = { form } >
@@ -535,7 +536,7 @@ describe('Form.Basic', () => {
535
536
536
537
it ( 'should trigger by setField' , ( ) => {
537
538
const triggerUpdate = jest . fn ( ) ;
538
- const formRef = React . createRef < FormInstance > ( ) ;
539
+ const formRef = React . createRef < FormRef > ( ) ;
539
540
540
541
render (
541
542
< div >
@@ -596,7 +597,7 @@ describe('Form.Basic', () => {
596
597
} ) ;
597
598
598
599
it ( 'setFieldsValue should clean up status' , async ( ) => {
599
- const form = React . createRef < FormInstance > ( ) ;
600
+ const form = React . createRef < FormRef > ( ) ;
600
601
let currentMeta : Meta = null ;
601
602
602
603
const { container } = render (
@@ -690,7 +691,7 @@ describe('Form.Basic', () => {
690
691
} ) ;
691
692
692
693
it ( 'filtering fields by meta' , async ( ) => {
693
- const form = React . createRef < FormInstance > ( ) ;
694
+ const form = React . createRef < FormRef > ( ) ;
694
695
695
696
const { container } = render (
696
697
< div >
@@ -857,7 +858,7 @@ describe('Form.Basic', () => {
857
858
} ) ;
858
859
859
860
it ( 'setFieldValue' , ( ) => {
860
- const formRef = React . createRef < FormInstance > ( ) ;
861
+ const formRef = React . createRef < FormRef > ( ) ;
861
862
862
863
const Demo : React . FC = ( ) => (
863
864
< Form ref = { formRef } initialValues = { { list : [ 'bamboo' , 'little' , 'light' ] } } >
@@ -894,7 +895,7 @@ describe('Form.Basic', () => {
894
895
895
896
it ( 'onMetaChange should only trigger when meta changed' , ( ) => {
896
897
const onMetaChange = jest . fn ( ) ;
897
- const formRef = React . createRef < FormInstance > ( ) ;
898
+ const formRef = React . createRef < FormRef > ( ) ;
898
899
899
900
const Demo : React . FC = ( ) => (
900
901
< Form ref = { formRef } >
@@ -920,7 +921,7 @@ describe('Form.Basic', () => {
920
921
describe ( 'set to null value' , ( ) => {
921
922
function test ( name : string , callback : ( form : FormInstance ) => void ) {
922
923
it ( name , async ( ) => {
923
- const form = React . createRef < FormInstance > ( ) ;
924
+ const form = React . createRef < FormRef > ( ) ;
924
925
925
926
const { container } = render (
926
927
< div >
@@ -953,7 +954,7 @@ describe('Form.Basic', () => {
953
954
954
955
it ( 'setFieldValue should always set touched' , async ( ) => {
955
956
const EMPTY_VALUES = { light : '' , bamboo : [ ] } ;
956
- const formRef = React . createRef < FormInstance > ( ) ;
957
+ const formRef = React . createRef < FormRef > ( ) ;
957
958
958
959
const Demo : React . FC = ( ) => (
959
960
< Form ref = { formRef } initialValues = { EMPTY_VALUES } >
0 commit comments