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.

Show expected and actual value for string equality

See original GitHub issue

When I compare two strings, the debugging output is not very helpful at the moment:

    it("strings are equal", () => {
      expect("a").toStrictEqual("b");
    });

prints

    ❌ strings are equal - 
      [Expected]: Reference Value
      [Actual]  : Reference Value

Would it be possible to create an output that helps understanding the problem (i.e. show expected and actual string)?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
webmaster128commented, Feb 3, 2020

Ah, I did not think of .toBe. I try to stick with some kind of equality matcher when I don’t explicitely want to test object identity.

0reactions
jtennercommented, Feb 5, 2020

@webmaster128 I wanted to mention that strings are immutable in nature, but using .toStrictEqual is a valid way to compare them, even if the functions that compare strings get used the same way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is Java's assertEquals method reliable? - Stack Overflow
You should always use .equals() when comparing Strings in Java. JUnit calls the .equals() method to determine equality in the method assertEquals(Object o1, ......
Read more >
Comparing Strings in Unit Tests | You've Been Haacked
Let's pretend the first value in the above test is the expected value and the second value is the value you obtained by...
Read more >
Comparing Strings with Java - Stack Abuse
String comparison is a common operation in all languages. The ability to check if one String is equal to another allows us to...
Read more >
Junit Assert & AssertEquals with Example - Guru99
It will return true if: expected.equals( actual ) returns true. Assert Array Equals. If you want to test equality of arrays, you have...
Read more >
The Ultimate Tutorial on String Comparison in Java - Simplilearn
The equality operator in Java is used to compare two or more objects. If it finds out that both the objects points or...
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