Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@emotion/jest Styles added through the css prop to a styled component are not captured in snapshots #3178

Open
yuryhtx opened this issue Apr 16, 2024 · 0 comments

Comments

@yuryhtx
Copy link

yuryhtx commented Apr 16, 2024

Current behavior:

The styles added with the css prop to a styled component are not captured in Snapshots when using @emotion/jest, but are applied as expected in the app

To reproduce:

The below code produces the following snapshot (note the lack of the color orange and height 50 styles in the snapshot):

import { css } from "@emotion/react";
import styled from "@emotion/styled";

const StyledP = styled.p`
  color: pink;
`;

export const Test = () => {
  return (
    <div>
      <StyledP
        css={css`
          color: orange;
          height: 50px;
        `}
      >
        styled with css
      </StyledP>
    </div>
  );
};

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
.emotion-0 {
  color: pink;
}

<div>
  <p
    className="emotion-0"
  >
    styled with css
  </p>
</div>
`;
  1. Create a styled component
  2. Apply additional styles to it by adding a css prop
  3. Take a snapshot
  4. Observe the lack of the styles added through the css prop in the snapshot

Expected behavior:

The styles should reflect the actual render on the web, and include the styles that are added through the css prop on styled components

Environment information:

"react": "^18.2.0",
"@emotion/jest": "^11.11.0"
"@emotion/react": "^11.11.1",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant