How to render styles for tests? #800
Replies: 13 comments 21 replies
-
Hey! What are you trying to test though? You shouldn't need to test that the styles are applied, that's Stitches' job. This repo does some basic tests: https://github.com/pffigueiredo/test-ui/blob/master/src/Button.test.tsx |
Beta Was this translation helpful? Give feedback.
-
Hi, @jonathantneal. Wondering if you or anyone else has had a chance to look into this. Having an issue where Any pointers appreciated! |
Beta Was this translation helpful? Give feedback.
-
FWIW, testing CSS using
|
Beta Was this translation helpful? Give feedback.
-
Hi folks. Has anyone had a chance to look into this further? We'd like to start moving our component library to use Stitches (currently on Has anyone been able to find a suitable workaround with Jest? |
Beta Was this translation helpful? Give feedback.
-
Hi all, Any updates here? same boat, I’d like to use ‘.toHaveStyle()’ in my unit tests. |
Beta Was this translation helpful? Give feedback.
-
We're in the same boat, too. We'd like to test defaults and overrides within our design system but unfortunately can't do it at the moment because of the lack of |
Beta Was this translation helpful? Give feedback.
-
I had a library for this called |
Beta Was this translation helpful? Give feedback.
-
I was working hard here at the company trying to indicate stitches in our project, but the test issue is making us back away from the difficulty of validating the applied classes as with styled-components using jest-styled-componets. Sad but I'll have to keep styled-components. Everything I see of example today doesn't include unit tests for component stitches. We have this gap for adoption |
Beta Was this translation helpful? Give feedback.
-
I think |
Beta Was this translation helpful? Give feedback.
-
Hi all, Any updates here? same boat, I’d like to use ‘.toHaveStyle()’ in my unit tests. |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, How do you suggest we test a show / hide toggle functionality? It currently feels like jest's |
Beta Was this translation helpful? Give feedback.
-
I'm having the same issues. using
const Button = ({ isDisabled = false, children, ...props }: ButtonProps) => {
return (
<ButtonStyled isDisabled={isDisabled} {...props}>
{children}
</ButtonStyled>
);
};
// button style
...
border: "1px solid #00C896", test code it("~~", () => {
render(<Quiz />);
const checkButton = screen.getByRole("button", { name: /정답 확인/i });
expect(checkButton).toHaveStyle(`border: 1px solid #00C896`);
}); I set it to 1px, but I don't know why 2px is coming out. https://github.com/hyjoong/quiz-app/blob/master/__tests__/quiz.test.jsx |
Beta Was this translation helpful? Give feedback.
-
In the year 2023, cars drive themselves, and AI rules the world, but we can't do something simple like test a component using "toBeVisible" because stitches don't work (and apparently will never work) with jsdom. Awesome! |
Beta Was this translation helpful? Give feedback.
-
When using something like
styled-components
we're able to render a component for testing and then test if that component has some style based on the use-case we want to test. With stitches, the rendered component only has classNames attached, but no reference to what styles those classNames apply, so there's no way to test styles based on conditions.Is there something we can do on a test renderer or on jest setup file to make those styles be applied to the components?
Beta Was this translation helpful? Give feedback.
All reactions