Update error message on assert when representation of expected and ac… #2303
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.
Purpose (TL;DR) - mandatory
Fixes issue #2084 by adding quotes to diff values if said values are strings, creating distinct string representations and preventing the expected and actual values from being reduced to a single value.
Background (Problem in detail) - optional
When the expected and actual values of an assertion do not match but they have the same string representation (for example the number 1234 and the string "1234"), the output does not show the difference, but reduces it to a single value. In this example, this output is produced:
expected spy to be called with arguments
1234
while this output was expected:
expected spy to be called with arguments
1234
1234
Solution - optional
A solution was proposed in the ticket itself which was also implemented here: adding quotes around a diff value if the value in question is a string. This process is skipped if the value is undefined, not a string, or already wrapped in quotes.
Instead, diffs are now displayed as follows, given the example where the string 1234 was expected but the number 1234 was found instead:
expected spy to be called with arguments
1234
'1234'
How to verify - mandatory
npm install
Checklist for author
npm run lint
passes