[PR #1] fix(date): Correct error message handling in chained date validations #1

Closed
opened 2026-03-07 21:30:02 +03:00 by kerem · 0 comments
Owner

Original Pull Request: https://github.com/ersinkoc/vld/pull/1

State: closed
Merged: Yes


Previously, when chaining date validation methods like min() and max(), the error message from the last validation would overwrite any previous messages. This resulted in incorrect error messages when an earlier validation in the chain failed.

This commit refactors the VldDate validator to associate each validation check with its own error message. The checks array in DateValidatorConfig now stores objects containing both the validation function and its corresponding message, ensuring that the correct error is thrown when a check fails.

A new test case has been added to verify that chained error messages are handled correctly. Additionally, the Jest configuration has been updated to properly handle ES Modules.

**Original Pull Request:** https://github.com/ersinkoc/vld/pull/1 **State:** closed **Merged:** Yes --- Previously, when chaining date validation methods like `min()` and `max()`, the error message from the last validation would overwrite any previous messages. This resulted in incorrect error messages when an earlier validation in the chain failed. This commit refactors the `VldDate` validator to associate each validation check with its own error message. The `checks` array in `DateValidatorConfig` now stores objects containing both the validation function and its corresponding message, ensuring that the correct error is thrown when a check fails. A new test case has been added to verify that chained error messages are handled correctly. Additionally, the Jest configuration has been updated to properly handle ES Modules.
kerem 2026-03-07 21:30:02 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vld#1
No description provided.