File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
packages/react-form-renderer/src Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,14 @@ describe('New validators', () => {
28
28
} ) ;
29
29
30
30
describe ( 'Length validator' , ( ) => {
31
+ it ( 'should pass empty value' , ( ) => {
32
+ expect ( validatorMapper ( validators . EXACT_LENGTH ) ( { threshold : 5 } ) ( '' ) ) . toBeUndefined ( ) ;
33
+ } ) ;
34
+
35
+ it ( 'should pass undefined value' , ( ) => {
36
+ expect ( validatorMapper ( validators . EXACT_LENGTH ) ( { threshold : 5 } ) ( undefined ) ) . toBeUndefined ( ) ;
37
+ } ) ;
38
+
31
39
it ( 'should pass exact length of 5 characters validation' , ( ) => {
32
40
expect ( validatorMapper ( validators . EXACT_LENGTH ) ( { threshold : 5 } ) ( '12345' ) ) . toBeUndefined ( ) ;
33
41
} ) ;
Original file line number Diff line number Diff line change @@ -21,7 +21,11 @@ export const length = memoize(({
21
21
equal = selectNum ( equal , is ) ;
22
22
min = selectNum ( min , minimum ) ;
23
23
max = selectNum ( max , maximum ) ;
24
- return prepare ( ( value = [ ] ) => {
24
+ return prepare ( ( value ) => {
25
+ if ( ! value ) {
26
+ return ;
27
+ }
28
+
25
29
if ( equal !== null && value . length !== equal ) {
26
30
const msg = prepareMsg ( message , 'wrongLength' , { count : equal } ) . defaultMessage ;
27
31
return typeof msg === 'string' ? msg : msg ( equal ) ;
You can’t perform that action at this time.
0 commit comments