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

@compiled/jest toHaveCompiledCss does not support advanced uses of ampersand #1669

Open
dddlr opened this issue May 10, 2024 · 0 comments
Open

Comments

@dddlr
Copy link
Collaborator

dddlr commented May 10, 2024

toHaveCompiledCss supports checking if a pseudo-selector has certain styles applied: https://compiledcssinjs.com/docs/pkg-jest#pseudo-selectors

With that in mind, we expect this Jest code to work:

const { getByText } = render(
  <div
    css={{
      '&:hover': {
        color: 'red',
      },
    }}>
    hello world
  </div>
);

const el = getByText('hello world');

expect(element).toHaveCompiledCss('color', 'red', {
  target: 'body &:hover',
});

However, toHaveCompiledCss doesn't know how to determine that body &:hover matches the el component. We should either extend toHaveCompiledCss to support this use case, or give an explicit error telling developers that this is not supported.

(Perhaps leaning towards the latter, as we want to discourage people from using nested / complicated selectors as part of the UI Styling Standard)

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

No branches or pull requests

1 participant