-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Describe the bug
The validateRequired test fails when validating a required dateTime field that is present in the data with a valid Date object.
Version/Branch
master
To Reproduce
Steps to reproduce the behavior:
-
Add the following test to the code:
it('Validating a dateTime that is required and present in the data with a valid date object will return null', async function () { const component = { ...simpleDateTimeField, validate: { required: true } }; const data = { component: new Date() }; const context = generateProcessorContext(component, data); const result = await validateRequired(context); expect(result).to.equal(null); });
-
Run the test.
-
Observe that it fails.
Expected behavior
The test should return null when validating a valid Date object for a required dateTime field.
Additional context
After reviewing the code, the issue is resolved by modifying the valueIsPresent function to correctly handle Date values. The proposed modification is as follows:
const valueIsPresent = (
value: any,
considerFalseTruthy: boolean,
isNestedDatatype?: boolean,
): boolean => {
if (
value === null ||
value === undefined ||
value === '' ||
(!considerFalseTruthy && value === false)
) {
return false;
} else if (isEmptyObject(value)) {
return false;
} else if (Array.isArray(value) && value.length === 0) {
return false;
} else if (value instanceof Date) {
return !isNaN(value.getTime());
} else if (typeof value === 'object' && !isNestedDatatype) {
return Object.values(value).some((val) =>
valueIsPresent(val, considerFalseTruthy, isNestedDatatype),
);
} else if (Array.isArray(value) && value.length) {
return doesArrayDataHaveValue(value);
}
return true;
};The modification was made in the file validateRequired.ts.
With this modification, the test passes correctly.
Metadata
Metadata
Assignees
Labels
No labels