Is there a recommended way of testing styles? #1233
Replies: 3 comments 1 reply
-
To address the first part of your question, if your consumers are using As for the second part of your question, I would agree that testing applied styles via snapshotting rendered HTML (or plain component JSX) isn't really worth it. At best these test only tell you that styles have been applied, but at worst they're a maintenance burden as they'll need to be updated every time a component style changes/the VE library is updated. IMO you can't really get any better than screenshot testing. Ultimately the visual appearance of your components is the "behaviour" of your styling API that's relevant to the user, so that's what you should test. This is the approach we took in Braid. These tests help catch visual regressions, and allow us to test behaviour that may be tricky/impossible to test programmatically, e.g. text wrapping, context-based colour/sizing, overlapping UI elements. We've found that by offering a high degree of visual consistency in our design system, combined with only exposing the |
Beta Was this translation helpful? Give feedback.
-
i also just had a problem testing styles. i have now identified it with regex. expect(svg).toHaveClass(/size_1_\w+/); |
Beta Was this translation helpful? Give feedback.
-
Having problems too with this, it is really necessary to test styles using vanilla-extract? |
Beta Was this translation helpful? Give feedback.
-
Hello, we have a React component library based on Vanilla Extract but we're having a bit helping consumers of the library test the styles (or CSS classes), e.g. we have utility sprinkles but the consumers are unable to identify which sprinkle classes are being set on a component due to the class name being hashed.
Is there any recommendations on testing styles applied via Vanilla Extract? We've previously suggested it's not recommended testing styling (especially with jest) outside the component library itself, otherwise we were looking at disabling the class name hashing as a last resort.
Beta Was this translation helpful? Give feedback.
All reactions