Firestore: equality_matcher.ts: fix missing custom assertion failure message in deep equals #7519
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug in Firestore's unit/integration testing framework where a "deep equals" assertion check would omit the custom failure message, when it should have included the custom failure message.
For example, consider the following "expect" checks:
Both of these checks will unconditionally fail because
{foo: 42}
does not "deep equal"{bar: 42}
. Also, both the checks specify a custom failure message to be incorporated into the failure message, albeit in different ways.The problem is that the custom message is not included in the ultimate failure message:
With the fix in this PR, the custom message is included in the failure message:
The root cause of the bug was the misconception that custom message would be specified as an argument to the function. The function signature was actually incorrectly typed as
(r: unknown, l: unknown) => boolean
, suggesting that it was supposed to comparer
andl
for equality. This coincidentally just happened to work becauser
was treated as the "expected" and thel
argument was simply ignored, which worked because it was always undefined anyways. The type was fixed to(expected: unknown) => void
.The custom function also did not need to call
utils.flag(this, 'message', msg)
because the chai testing framework already makes this call, and when the custom function made the call it just clobbered the previously-set custom message withundefined
.