Skip to content

test: add unit tests for hasValidation logic #12934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kamja44
Copy link
Contributor

@kamja44 kamja44 commented Jul 4, 2025

Add complete unit tests for hasValidation covering all rule branches and edge cases

This PR adds unit tests for the hasValidation function.

  • Covers all validation rule branches: required, min, max, minLength, maxLength, pattern, and validate
  • Tests both truthy and falsy conditions, including:
    • required as string and boolean
    • 0 as falsy input for numeric rules
    • pattern as RegExp or object
    • validate as function or object
  • Verifies that mount is required for validation to pass
  • Ensures hasValidation returns false when:
    • no validation rule is provided
    • validation values are explicitly falsy (e.g., false, undefined, null)
    • pattern is provided without valueAsDate/valueAsNumber

This improves the reliability of the validation logic by ensuring that all edge cases and possible value combinations are covered. It also eliminates reliance on as any through type-safe test field definitions.

@kamja44 kamja44 force-pushed the test/add-hasValidation-unit-tests branch from 0cb521b to eb8915a Compare July 4, 2025 07:22
@bluebill1049 bluebill1049 merged commit 62c6a82 into react-hook-form:master Jul 5, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants