-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add nested property operations with Chai compatibility #227
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
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 implements comprehensive nested property assertion support using dot notation (e.g., a.b.c) and bracket notation (e.g., a[0]), along with Chai.js compatibility. It adds new assertion functions for checking nested properties with both loose and deep equality, enhances error handling with showDiff and operator properties, and provides full integration with both assert and expect APIs.
Changes:
- Added nested property operations with path parsing supporting dot notation, bracket notation, and escape sequences
- Implemented
nestedProperty,deepNestedProperty,nestedInclude, anddeepNestedIncludeassertions with negation variants - Enhanced
AssertionErrorwith readonlyoperatorandshowDiffproperties for better error reporting - Integrated nested operations into
IHasOpandIDeepOpinterfaces for fluent API chaining
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| core/src/assert/funcs/nested.ts | Implements path parsing and nested property assertion logic with support for dot/bracket notation |
| core/src/assert/ops/nestedOp.ts | Creates operation wrappers for nested and deep nested property assertions |
| core/src/assert/interface/ops/INestedOp.ts | Defines TypeScript interface for nested property operations |
| core/src/assert/ops/hasOp.ts | Integrates nested operations into the has operation chain |
| core/src/assert/ops/deepOp.ts | Integrates deep nested operations into the deep operation chain |
| core/src/assert/assertClass.ts | Registers nested assertion functions in the main assert class |
| core/src/assert/assertionError.ts | Adds readonly properties for operator and showDiff with helper function |
| core/src/assert/scopeContext.ts | Includes showDiff in context details and fixes typo in documentation |
| core/src/assert/config.ts | Adds default showDiff: true configuration option |
| core/src/assert/interface/IAssertConfig.ts | Defines showDiff configuration property |
| core/src/assert/interface/IAssertClass.ts | Adds TypeScript definitions for new nested assertion methods |
| core/src/assert/interface/ops/IHasOp.ts | Extends interface with nested property operation |
| core/src/assert/interface/ops/IDeepOp.ts | Extends interface with deep nested property operation |
| core/src/assert/funcs/hasProperty.ts | Updates default error messages for property assertions |
| core/src/assert/ops/includeOp.ts | Renames parameters for consistency |
| core/src/index.ts | Exports INestedOp interface publicly |
| core/test/src/assert/parseNestedPath.test.ts | Comprehensive tests for path parsing with various notations and edge cases |
| core/test/src/assert/assert.nested.test.ts | Tests for all nested property assertion functions |
| core/test/src/assert/context.test.ts | Updates tests to expect showDiff in context details |
| core/test/src/assert/assertionError.test.ts | Tests for new readonly properties on AssertionError |
| core/test/src/support/checkError.ts | Makes match parameter required (breaking change) |
| shim/chai/src/assert/chaiAssert.ts | Implements Chai compatibility adapters for nested assertions |
| shim/chai/test/src/chaiAssert.test.ts | Enables and updates Chai compatibility tests for nested operations |
Implement comprehensive support for nested property assertions using dot notation (e.g., a.b.c) and bracket notation (e.g., a[0]). New Assertions: - nestedProperty / notNestedProperty - Check nested properties with loose equality - deepNestedProperty / notDeepNestedProperty - Check nested properties with deep equality - nestedInclude / notNestedInclude - Match nested properties against expected object - deepNestedInclude / notDeepNestedInclude - Deep match nested properties Features: - Dot notation: a.b.c - Bracket notation: a[0], a[b] - Mixed paths: a.b[0].c - Escape sequences: \.a, \[b\] for literal dots/brackets API Extensions: - Added INestedOp<R> interface with property, include, includes, contain, contains methods - Integrated with IHasOp and IDeepOp operation chains - Supports both assert and expect syntax Error Enhancements: - Added operator and showDiff readonly properties to AssertionError - Added showDiff configuration option (default: true) - Improved error messages with better context for nested property failures Chai Shim: - Implemented nestedProperty, notNestedProperty, nestedPropertyVal, notNestedPropertyVal - Implemented deepNestedPropertyVal, notDeepNestedPropertyVal - Implemented nestedInclude, notNestedInclude, deepNestedInclude, notDeepNestedInclude
Implement comprehensive support for nested property assertions using dot notation (e.g., a.b.c) and bracket notation (e.g., a[0]).
New Assertions:
Features:
API Extensions:
Error Enhancements:
Chai Shim: