Skip to content

Conversation

@lambdalisue
Copy link
Member

Summary

  • Remove automatic property existence check in toHavePropertySatisfying
  • Remove ensureNonNullish validation that rejected null/undefined values
  • Allow matcher to receive any value including null, undefined, or non-existent properties
  • Add comprehensive test cases for null values and broken object paths

Why

The toHavePropertySatisfying method 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:

  1. Validating null values: Users couldn't check if a property is explicitly null
  2. Checking non-existence: Users couldn't verify that a property should not exist
  3. Handling broken paths: Users couldn't validate behavior when intermediate properties are null/undefined

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 PropertySatisfying with its design principle: delegate all validation logic to the user.

Test Plan

  • All existing tests pass (1106 tests)
  • New test: Validate null property values
  • New test: Validate undefined values from broken intermediate paths (null)
  • New test: Validate undefined values from broken intermediate paths (undefined)
  • Verify matcher receives actual values without automatic filtering

Copilot AI review requested due to automatic review settings January 9, 2026 02:13
@lambdalisue lambdalisue enabled auto-merge January 9, 2026 02:14
@codecov
Copy link

codecov bot commented Jan 9, 2026

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
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ensureNonNullish validation 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.

@lambdalisue lambdalisue merged commit ad08a72 into main Jan 9, 2026
3 checks passed
@lambdalisue lambdalisue deleted the fix/satisfying branch January 9, 2026 02:20
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