File tree 2 files changed +30
-1
lines changed
src/process/validation/rules
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -71,3 +71,32 @@ it('A simple component with JSON logic evaluation will return null if the JSON l
71
71
const result = await validateJson ( context ) ;
72
72
expect ( result ) . to . equal ( null ) ;
73
73
} ) ;
74
+
75
+ it ( 'A simple component with JSON logic evaluation will validate even if the value is falsy' , async ( ) => {
76
+ const component = {
77
+ ...simpleTextField ,
78
+ validate : {
79
+ json : {
80
+ if : [
81
+ {
82
+ '===' : [
83
+ {
84
+ var : 'input' ,
85
+ } ,
86
+ 'foo' ,
87
+ ] ,
88
+ } ,
89
+ true ,
90
+ "Input must be 'foo'" ,
91
+ ] ,
92
+ } ,
93
+ } ,
94
+ } ;
95
+ const data = {
96
+ component : '' ,
97
+ } ;
98
+ const context = generateProcessorContext ( component , data ) ;
99
+ const result = await validateJson ( context ) ;
100
+ expect ( result ) . to . be . instanceOf ( FieldError ) ;
101
+ expect ( result ?. errorKeyOrMessage ) . to . contain ( "Input must be 'foo'" ) ;
102
+ } ) ;
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { isObject } from 'lodash';
6
6
7
7
export const shouldValidate = ( context : ValidationContext ) => {
8
8
const { component, value } = context ;
9
- if ( ! value || ! component . validate ?. json || ! isObject ( component . validate . json ) ) {
9
+ if ( ! component . validate ?. json || ! isObject ( component . validate . json ) ) {
10
10
return false ;
11
11
}
12
12
return true ;
You can’t perform that action at this time.
0 commit comments