Having issues running React snapshot tests with Preact #4119
Replies: 1 comment 3 replies
-
How are you generating your snapshots? RTS will transform |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working on a React design system project that also provides a Preact version of the code. We're using all the aliasing documented in Preact's docs (Jest, Webpack). Things are running pretty smoothly, but we are noticing when we run Preact against our unit tests (which use React) many snapshot tests fail.
Looking at the broken snapshot tests, there appears to be a difference between how React and Preact treat falsey values; many of the snapshots have an attribute set to an empty string; React seems to handle these as expected but Preact strips them out, resulting in the broken snapshot test.
For instance, we have a checkbox component with a
checked
property. In the unit test, we setprops.checked = true
and the snapshot generates something like the following:React:
Preact:
React's code indicates the checkbox is checked, however because it's falsey (empty string) Preact strips it out. At least that's our assumption based on this code we've found in the Preact project.
Is there some kind of configuration we can set with preact/compat to ignore removing falsey attributes? Or do you know of a way to get React to behave more inline with Preact?
Beta Was this translation helpful? Give feedback.
All reactions