Show expected and actual value for string equality
See original GitHub issueWhen 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:
- Created 4 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Top 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 >
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 Free
Top 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
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.@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.