hamjest
hamjest copied to clipboard
Diff for `hasProperties`
When using hasProperties
we are more interested in the given properties than in anything else. So the diff becomes more useful if only the differing aspects are shown. describeMismatch
uses a similar reasoning.
In order to do this, I had to change the diff API. Cp. https://github.com/rluba/hamjest/pull/7#issuecomment-66612504 I refactored the early beginnings that we had so far.
When creating the diff objects in hasProperties
, I considered the following situations:
- direct properties (implicit equalTo)
- diff-capable matcher
- non-diff-capable matcher
- multiple nesting, e.g.
__.hasProperties({a: __.hasProperties({b: __.greaterThan(2)})})
Real-life example
Before
After
(with a custom property matcher for nicer formatting)
Hi Alex,
thank you for the pull request and sorry for the delay.
Looks great, but I think your hasProperties.getDiffItems
breaks if hasProperties
is a promising matcher due to promising sub-matchers. Retaining promise-awareness can be quite tricky, event when using promiseAgnostic
.
Do you think you can update the PR accordingly?
Although I doubt that anyone already uses the diff API for custom matchers, I will nonetheless increase the major version when merging due to the breaking API changes.