-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(bupkis): consolidate satisfy and deep equal assertions #338
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
Conversation
Replaces 6 type-specific assertions with 2 generic versions: - objectSatisfiesAssertion + arraySatisfiesAssertion → satisfiesAssertion - object/array/map/setDeepEqualAssertion → deepEqualAssertion Both now accept unknown subjects and parameters, delegating type validation to valueToSchema. This simplifies the API while maintaining equivalent behavior for same-type comparisons. Includes updated property tests, snapshot tests, and new unit tests covering primitive equality cases.
…ction
Adds a new 'permissivePropertyCheck' option to valueToSchema that
allows checking object properties on any value type (functions,
arrays, etc.), not just plain objects. Properties are checked
using the 'in' operator which works with non-enumerable and
inherited properties.
This enables use cases like:
- expect([1,2,3], 'to satisfy', {length: 3})
- expect(Promise, 'to satisfy', {reject: expect.it('to be a function')})
The option is automatically enabled for 'to satisfy' assertions
via valueToSchemaOptionsForSatisfies.
Includes comprehensive tests for cross-type satisfaction scenarios.
…ases - Add literalEmptyArrays option: when false (default), empty arrays [] match any array (like literalEmptyObjects for objects) - Fix permissive property check for array elements: disable permissive mode inside arrays to avoid union conflicts with z.any() - Handle inaccessible properties (arguments/caller/callee on strict mode functions) gracefully with try/catch - Add comprehensive property tests for permissivePropertyCheck option covering functions, arrays, classes, getters, and edge cases
- Move 'to satisfy' from object.md to equality.md - Expand 'to deep equal' examples to show primitives, Map, Set - Add cross-type satisfaction examples (arrays with length, Promise) - Replace redundant Map/Set deep equal sections with redirects - Add redirects in object.md and collection.md pointing to equality.md
There was a problem hiding this 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 consolidates six type-specific assertions ({object}, {array}, {Map}, {Set} variants of to satisfy and to deep equal) into two generic assertions that work with any value type. The consolidation enables a new "cross-type satisfaction" feature where properties can be validated on any value that has them (arrays, functions, constructors, etc.).
Changes:
- Consolidated 6 type-specific assertions into 2 generic ones:
{unknown} to satisfy {unknown}and{unknown} to deep equal {unknown} - Added
permissivePropertyCheckoption to enable property validation on non-object types using theinoperator - Added
literalEmptyArraysoption to control whether empty arrays match any array (similar to existingliteralEmptyObjects)
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| site/assertions/object.md | Replaced detailed to satisfy documentation with redirect to equality.md |
| site/assertions/equality.md | Added comprehensive documentation for consolidated to satisfy and expanded to deep equal with primitives, Maps, Sets examples |
| site/assertions/collection.md | Added redirects for array/Map/Set specific assertions to consolidated versions |
| packages/bupkis/test/property/value-to-schema.test.ts | Added 17 property tests for permissivePropertyCheck covering functions, arrays, classes, getters, edge cases |
| packages/bupkis/test/assertion/satisfy-deep-equal.test.ts | New test file with 396 lines covering primitives, objects, arrays, cross-type satisfaction, negation, edge cases |
| packages/bupkis/test/property/configs/sync-parametric.ts | Updated test configurations to use consolidated assertions with expanded test cases for primitives |
| packages/bupkis/test/assertion/assertion-classification.test.ts | Updated assertion count from 86 to 82 (net reduction of 4 after consolidation) |
| packages/bupkis/test/assertion-error/*.snapshot | Updated snapshots to reflect new assertion IDs |
| packages/bupkis/test/assertion-error/sync-parametric-error.test.ts | Updated to use consolidated assertions |
| packages/bupkis/test-data/sync-parametric-generators.ts | Consolidated generators to support primitives, objects, arrays, Maps, Sets |
| packages/bupkis/src/value-to-schema.ts | Added literalEmptyArrays and permissivePropertyCheck options with comprehensive implementation |
| packages/bupkis/src/assertion/impl/sync.ts | Updated exports to remove type-specific assertions |
| packages/bupkis/src/assertion/impl/sync-parametric.ts | Replaced 6 type-specific assertions with 2 generic ones |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Update @bupkisAssertionCategory from 'comparison' to 'equality' and fix @bupkisAnchor to match documentation anchors.
…emantics Empty arrays [] now mean 'any array' in satisfaction mode, so invalid tests must use non-empty expected args to actually test argument mismatches in event emission assertions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Consolidates the type-specific
to satisfyandto deep equalassertions into single generic versions that work on any value type.Changes
Assertion Consolidation
Before: 6 type-specific assertions
{object} to satisfy {any}{array} to satisfy {any}{object} to deep equal {object}{array} to deep equal {array}{Map} to deep equal {Map}{Set} to deep equal {Set}After: 2 generic assertions
{unknown} to satisfy {unknown}{unknown} to deep equal {unknown}New Feature: Cross-Type Satisfaction
The consolidated
to satisfyassertion now supports validating properties on any value that has them:New
valueToSchemaOptionsliteralEmptyArrays: Whenfalse(default), empty arrays[]match any array (likeliteralEmptyObjectsfor objects)permissivePropertyCheck: Whentrue, validates object shapes against any value with properties (functions, arrays, etc.) using theinoperatorDocumentation
to satisfydocumentation fromobject.mdtoequality.mdto deep equalexamples to show primitives, Map, SetTesting
permissivePropertyCheckcovering functions, arrays, classes, getters, and edge casesarguments,caller,calleeon strict mode functions)