diff --git a/src/process/validation/rules/__tests__/validateJson.test.ts b/src/process/validation/rules/__tests__/validateJson.test.ts index d4d529e8..5340dbc7 100644 --- a/src/process/validation/rules/__tests__/validateJson.test.ts +++ b/src/process/validation/rules/__tests__/validateJson.test.ts @@ -71,3 +71,32 @@ it('A simple component with JSON logic evaluation will return null if the JSON l const result = await validateJson(context); expect(result).to.equal(null); }); + +it('A simple component with JSON logic evaluation will validate even if the value is falsy', async () => { + const component = { + ...simpleTextField, + validate: { + json: { + if: [ + { + '===': [ + { + var: 'input', + }, + 'foo', + ], + }, + true, + "Input must be 'foo'", + ], + }, + }, + }; + const data = { + component: '', + }; + const context = generateProcessorContext(component, data); + const result = await validateJson(context); + expect(result).to.be.instanceOf(FieldError); + expect(result?.errorKeyOrMessage).to.contain("Input must be 'foo'"); +}); diff --git a/src/process/validation/rules/validateJson.ts b/src/process/validation/rules/validateJson.ts index de333b1a..68c879a7 100644 --- a/src/process/validation/rules/validateJson.ts +++ b/src/process/validation/rules/validateJson.ts @@ -6,7 +6,7 @@ import { isObject } from 'lodash'; export const shouldValidate = (context: ValidationContext) => { const { component, value } = context; - if (!value || !component.validate?.json || !isObject(component.validate.json)) { + if (!component.validate?.json || !isObject(component.validate.json)) { return false; } return true;