Answer the question
In order to leave comments, you need to log in
How to test styles in react?
The component accepts 2 props:
- borderColor, and if it is passed - the color of the button's border should change
- children
const Button = ({borderColor, children}) => {
return (
<button style={{borderColor: borderColor ? `border: 1px solid ${borderColor}` : null}}>
{children}
</button>
)
}
Answer the question
In order to leave comments, you need to log in
jest-dom has a toHaveStyle matcher.
About testing all props: you chose the wrong library. The React Testing Library is more about testing logic from the user's point of view, i.e. omitting implementation details.
For unit testing React components, enzyme is more suitable.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question