question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest-diff returns null if one string is multiline but the other is not

See original GitHub issue

Do 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:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
SimenBcommented, May 1, 2018

I think we should fix this before releasing Jest 23.

whether it will seem like a step backward in developer experience if it reports a failure as follows

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.

1reaction
thymikeecommented, Mar 26, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found