Allow PropertySatisfying matcher to handle null/undefined values#21
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ll/undefined values Previously, toHavePropertySatisfying performed automatic property existence checks and rejected null/undefined values before calling the matcher. This prevented users from validating null values, checking for non-existent properties, or handling broken object paths. Since PropertySatisfying is designed for custom user-defined validation logic, users should have full control over all validation aspects, including property existence checks. This change removes the automatic guards and always invokes the matcher with the actual value (or undefined if the property path is invalid). Changes: - Remove toHaveProperty existence check before matcher execution - Remove ensureNonNullish call that rejected null/undefined - Simplify error handling to only report matcher failures - Add test cases for null values and broken intermediate paths
886262d to
ced83fc
Compare
There was a problem hiding this comment.
Pull request overview
This PR modifies the toHavePropertySatisfying matcher to remove automatic property existence validation and null/undefined checks, allowing users complete control over validation logic including checking null values, non-existent properties, and broken object paths.
Key Changes:
- Removed automatic property existence check using
stdExpect(obj).toHaveProperty() - Removed
ensureNonNullishvalidation that rejected null/undefined values - Simplified implementation to directly call user's matcher with any value including null/undefined
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/probitas-expect/mixin/object_value_mixin.ts | Removed property existence check and ensureNonNullish call from toHavePropertySatisfying, allowing matcher to receive any value including null/undefined |
| packages/probitas-expect/mixin/object_value_mixin_test.ts | Added three new test cases: null value validation, broken path with null intermediate, and broken path with undefined intermediate |
| packages/probitas-expect/mixin/snapshots/object_value_mixin_test.ts.snap | Updated line numbers in snapshots due to new test cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
toHavePropertySatisfyingensureNonNullishvalidation that rejected null/undefined valuesWhy
The
toHavePropertySatisfyingmethod is designed for user-defined custom validation logic. Previously, it automatically validated property existence and rejected null/undefined values before calling the user's matcher function. This prevented legitimate use cases:Since this method is meant to give users complete control over validation logic, the automatic guards were too restrictive. By removing these constraints, users can now implement any validation scenario they need, including property existence checks within their matcher function.
This change aligns
PropertySatisfyingwith its design principle: delegate all validation logic to the user.Test Plan