Open yuuta1999 opened 4 years ago
I would just assert that Button
has the correct variable name applied:
expect(tree).toHaveStyleRule('color', 'var(--Button--Color)')
And test GlobalStyle separately for the actual colour value. It is probably easiest to use snapshot testing for createGlobalStyle as it creates multiple styling rules. Somebody may be able to offer an alternative solution.
It is also best practice to wrap global CSS variables in :root
:
// GlobalStyle.jsx
const GlobalStyle = createGlobalStyle`
:root{
--Button--Color: ${props => props.mode === 'light' ? '#fff' : '#000};
--Buton--Background: ${props => props.mode === 'light' ? "#000" : "#fff"};
}
`
I created my blog with styled-components and everything worked perfectly. I think testing will help me cover all the errors and bugs that I didn't see, so I decided to test the whole website. But I had troubles from the beginning. Every code examples demonstrated testing on pass-props components, like this:
and its test will look like this:
My whole codebase is too different from these examples. For instance:
How can I test styled-components in this situation? Every comments are appreciated to me.