Open lydell opened 1 year ago
Yeah, this is the major breaking change of Jest 29: https://jestjs.io/blog/2022/08/25/jest-29
Ergh, your example doesn't look too good, tho 😅 Anything we can do about that? I don't think we want to escape newlines in a string literal - I have a bunch of e.g. table or csv inline snapshots at work that should definitely render out the newlines and not escape them.
/cc @orta
I think we probably want to look for newlines in the value and switch the outer character from a quote to an escaped backtick? That can keep the multi-line-ness and still describe the text - it also means the code can still be C&P'd in theory, though the backticks would get lost
But at least looking at the test, the string it is representing is the string ""
so """"
is a silly but reasonable answer because you wouldn't want it to be ""
🍡
Btw, I really like the snapshot defaults in Jest 29, makes snapshots much easier to read in general.
If we can come up with some clever way to improve these edge cases that might be nice. Otherwise it might just be about getting used to it.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Hi @github-actions! See you again in a month or two!
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Version
29.3.1
Steps to reproduce
index.test.js
.npm it
to verify the snapshots.Expected behavior
I expected double quotes in strings to be escaped in snapshots.
Actual behavior
Double quotes are not escaped.
Additional context
I updated from Jest 28 to 29 and was surprised seeing this in my snapshot after updating it:
https://github.com/lydell/js-tokens/commit/368dd65d3e126b2d8d9283ef4c141c0f027aa9c2#diff-fe86fc96fcb8e216d5f567cd722b97c78783f153bb86e01b82e02fad7d1354fdR32
I was like – “
""""
? What’s up with that?” And then “Ooooh! It’s the empty string … as a string … in a snapshot string 🙃 ”Wanted to check if this is expected behavior or not?
It allows you to do fun things like this – how many properties does the object have?
Environment