feat(core): Add new matchers and improve negation messaging
This commit is contained in:
@ -21,17 +21,35 @@ This document captures the roadmap for evolving the `expect` / `expectAsync` API
|
||||
- [ ] Group matchers under `.string`, `.array`, `.number`, etc. for discoverability.
|
||||
|
||||
## Phase 6: Jest-Style Convenience
|
||||
- [ ] Add `.toMatchObject()`, `.toMatchSnapshot()`, `expect.any()`, `expect.anything()`, etc.
|
||||
- [x] Add `expect.any()` and `expect.anything()` matchers for use in `.toMatchObject()` patterns
|
||||
(Snapshot matchers still TBD)
|
||||
|
||||
## Phase 7: Error Messages & Diffs
|
||||
- [ ] Integrate a diffing library for clear failure output with colorized diffs.
|
||||
The next items to tackle:
|
||||
|
||||
## Phase 8: Nested Access Chaining
|
||||
- [ ] Provide `.at(path)` or lens-based API for deep property assertions in one go.
|
||||
3. Improve negation (`.not`) messaging
|
||||
- Today `.not` simply flips pass/fail, but the failure message isn’t very descriptive. We should capture positive/negative message templates so e.g.
|
||||
> expect(5).not.toBeGreaterThan(3)
|
||||
emits:
|
||||
"Expected 5 not to be greater than 3"
|
||||
|
||||
## Phase 9: Pluggable Reporters
|
||||
- [ ] Allow consumers to swap output format: JSON, TAP, HTML, etc.
|
||||
4. Richer error output for objects/arrays
|
||||
- Integrate a diff library (or extend `fast-deep-equal`) to show unified diffs between expected and actual values
|
||||
|
||||
## Phase 10: API Cleanup
|
||||
- [ ] Audit and remove legacy aliases and redundant methods.
|
||||
- [ ] Finalize deprecations and bump to a major version.
|
||||
5. More built-in matchers
|
||||
- toBeNaN(), toBeFinite()
|
||||
- toBeWithinRange(min, max)
|
||||
- toHaveKeys(...), toHaveOwnKeys(...)
|
||||
- toThrowErrorMatching(/regex/), toThrowErrorWithMessage('…')
|
||||
- string/array: toBeEmpty() alias
|
||||
- object: toHaveOwnProperty() shorthand
|
||||
|
||||
6. TypeScript-friendliness
|
||||
- Enhance `.d.ts` so editors autocomplete namespace methods (e.g. `expect(x).string.`)
|
||||
- Statically type matcher arguments to catch wrong types at compile time
|
||||
|
||||
7. Async assertions and timeouts improvements
|
||||
- Support `.not.resolves`, `.rejects.toThrow()`
|
||||
- Provide clearer timeout errors (e.g. "Expected promise to resolve within …")
|
||||
|
||||
8. Plugin/extension API
|
||||
- Formalize `Assertion.extend()` plugin API for shipping matcher bundles
|
Reference in New Issue
Block a user