jest-diff returns null if one string is multiline but the other is not
See original GitHub issueDo you want to request a feature or report a bug?
bug
What is the current behavior?
https://repl.it/@sompylasar/jest-diff-multiline-vs-oneline
jest-diff@22.1.0
----------- a === "foo\nbar\nbaz"
foo
bar
baz
----------- b === "foo\n"
foo
----------- diff:
- Expected
+ Received
foo
- bar
- baz
+
-----------
----------- a === "foo\nbar\nbaz"
foo
bar
baz
----------- b === "foo"
foo
----------- diff:
null
-----------
----------- a === "foo"
foo
----------- b === "foo\n"
foo
----------- diff:
null
-----------
----------- a === "foo"
foo
----------- b === "foo\nbar"
foo
bar
----------- diff:
null
-----------
What is the expected behavior?
----------- a === "foo\nbar\nbaz"
foo
bar
baz
----------- b === "foo\n"
foo
----------- diff:
- Expected
+ Received
foo
- bar
- baz
+
-----------
----------- a === "foo\nbar\nbaz"
foo
bar
baz
----------- b === "foo"
foo
----------- diff:
- Expected
+ Received
foo
- bar
- baz
-----------
----------- a === "foo"
foo
----------- b === "foo\n"
foo
----------- diff:
- Expected
+ Received
foo
+
-----------
----------- a === "foo"
foo
----------- b === "foo\nbar"
foo
bar
----------- diff:
- Expected
+ Received
foo
+ bar
-----------
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
jest-diff - npm
The returned string consists of: annotation lines: describe the two change indicators with labels, and a blank line; comparison lines: similar ...
Read more >Ruby: Can I write multi-line string with no concatenation?
If proper indentation is not a concern, then single and double quotes can span multiple lines in Ruby: conn.exec "select attr1, attr2, attr3,...
Read more >Jest - Displaying Diffs [TypeScript] - Code Catalog
The diff named export serializes JavaScript values, compares them line-by-line, and returns a string which includes comparison lines.
Read more >client/node_modules/jest-diff - GitLab
Three named exports compare arrays of strings line-by-line: diffLinesUnified and diffLinesUnified2 return a string. diffLinesRaw returns an ...
Read more >jest-diff | Yarn - Package Manager
The diff named export serializes JavaScript values, compares them line-by-line, and returns a string which includes comparison lines.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think we should fix this before releasing Jest 23.
We can always improve the error message in Jest afterwards, but making
jest-diff
behave correctly doesn’t have to be blocked by it, IMO.The tests were added later by @pedrottimark to document the behavior. Here’s a rough explanation: https://github.com/jest-community/snapshot-diff/pull/27#discussion_r165079275
All in all, looks like it’s about time to fix this and make it right for a generic use case, not only for
expect
matchers.