hamjest icon indicating copy to clipboard operation
hamjest copied to clipboard

Diff for `hasProperties`

Open alexbepple opened this issue 10 years ago • 1 comments

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

screen shot 2014-12-11 at 13 52 42

After

(with a custom property matcher for nicer formatting)

screen shot 2014-12-11 at 20 12 28

alexbepple avatar Dec 11 '14 19:12 alexbepple

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.

rluba avatar Jan 07 '15 16:01 rluba