1
- import React , { useState , useMemo , Component , RefObject , createRef , forwardRef , useImperativeHandle } from 'react' ;
1
+ import React , {
2
+ useState ,
3
+ useMemo ,
4
+ Component ,
5
+ type RefObject ,
6
+ createRef ,
7
+ forwardRef ,
8
+ useImperativeHandle ,
9
+ PureComponent ,
10
+ isValidElement ,
11
+ } from 'react' ;
2
12
import { Input , Form } from '@alifd/next' ;
3
13
import Field from '../src' ;
4
14
@@ -28,7 +38,7 @@ describe('field', () => {
28
38
29
39
describe ( 'render' , ( ) => {
30
40
it ( 'should support Form' , ( ) => {
31
- class Demo extends React . Component {
41
+ class Demo extends Component {
32
42
field = new Field ( this ) ;
33
43
34
44
render ( ) {
@@ -77,11 +87,11 @@ describe('field', () => {
77
87
} ) ;
78
88
79
89
it ( 'should support React.createRef in Form' , ( ) => {
80
- class Demo extends React . Component < {
90
+ class Demo extends Component < {
81
91
onClick : ( ref : RefObject < any > ) => void ;
82
92
} > {
83
93
field = new Field ( this ) ;
84
- ref = React . createRef < any > ( ) ;
94
+ ref = createRef < any > ( ) ;
85
95
render ( ) {
86
96
return (
87
97
< Form field = { this . field } >
@@ -109,7 +119,7 @@ describe('field', () => {
109
119
} ) ;
110
120
111
121
it ( 'should support PureComponent' , ( ) => {
112
- class Demo extends React . PureComponent {
122
+ class Demo extends PureComponent {
113
123
field = new Field ( this , { forceUpdate : true } ) ;
114
124
115
125
render ( ) {
@@ -127,7 +137,7 @@ describe('field', () => {
127
137
} ) ;
128
138
129
139
it ( 'should support origin input/checkbox/radio' , ( ) => {
130
- class Demo extends React . Component {
140
+ class Demo extends Component {
131
141
field = new Field ( this ) ;
132
142
133
143
render ( ) {
@@ -341,7 +351,7 @@ describe('field', () => {
341
351
} ) ;
342
352
343
353
it ( 'should support control through `setState`' , ( ) => {
344
- class Demo extends React . Component {
354
+ class Demo extends Component {
345
355
state = {
346
356
show : true ,
347
357
inputValue : 'start' ,
@@ -370,7 +380,7 @@ describe('field', () => {
370
380
} ) ;
371
381
372
382
it ( 'should support control through `setState` when `parseName` is true' , ( ) => {
373
- class Demo extends React . Component {
383
+ class Demo extends Component {
374
384
state = {
375
385
show : true ,
376
386
inputValue : 'start' ,
@@ -434,14 +444,14 @@ describe('field', () => {
434
444
} ) ;
435
445
} ) ;
436
446
437
- describe ( 'behaviour ' , ( ) => {
447
+ describe ( 'behavior ' , ( ) => {
438
448
it ( 'getValue & getValues & setValue & setValues' , ( ) => {
439
449
const field = new Field ( { } ) ;
440
450
field . init ( 'input' , { initValue : 1 } ) ;
441
451
field . init ( 'input2' , { initValue : 2 } ) ;
442
452
field . init ( 'input3.name' , { initValue : 3 } ) ;
443
453
444
- field . setValue ( 'input' , 2 ) ;
454
+ field . setValue < number > ( 'input' , 2 ) ;
445
455
assert ( field . getValue ( 'input' ) === 2 ) ;
446
456
assert ( field . getValue ( 'input3.name' ) === 3 ) ;
447
457
assert ( Object . keys ( field . getValues ( ) ) . length === 3 ) ;
@@ -524,7 +534,7 @@ describe('field', () => {
524
534
assert ( field . getError ( 'input2' ) ?. [ 0 ] === 'error 2' ) ;
525
535
526
536
field . setError ( 'input' , < span > hello</ span > ) ;
527
- assert ( React . isValidElement ( field . getError ( 'input' ) ?. [ 0 ] ) === true ) ;
537
+ assert ( isValidElement ( field . getError ( 'input' ) ?. [ 0 ] ) === true ) ;
528
538
} ) ;
529
539
it ( 'getState' , ( ) => {
530
540
const field = new Field ( { } ) ;
0 commit comments