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

Is there any ways to get style for pseudo-class? #35

Open
Ailrun opened this issue Apr 11, 2018 · 6 comments
Open

Is there any ways to get style for pseudo-class? #35

Ailrun opened this issue Apr 11, 2018 · 6 comments

Comments

@Ailrun
Copy link
Collaborator

Ailrun commented Apr 11, 2018

  • jest-glamor-react version: v4.2.1
  • node version: v8.9.4
  • npm (or yarn) version: v5.6.0

Relevant code or config

const TestComp = glamorous.div({
  '::after': {
    backgroundColor: 'white',
  },
});

it('should have white background', () => {
  const component = enzyme.shallow(<TestComp />);
  expect(component).toHaveStyleRule(/* What should I do ??? */);
});

What you did:
Try to test pseudo-class style

What happened:
No way to test it

Problem description:

Suggested solution:
Add some matchers? or add functions to the matcher?

@Ailrun
Copy link
Collaborator Author

Ailrun commented Apr 11, 2018

and thank you for great library!

@kentcdodds
Copy link
Owner

I'm afraid I don't think that's currently supported.

If we could make it work with jest-dom that would be sweet. Then you could use this: testing-library/jest-dom#6

@kentcdodds
Copy link
Owner

Either way, I think this would be great:

expect(component).toHaveStyleRule({
  '::after': {
    backgroundColor: 'white',
  },
})

I'm not sure how to do that though and I'm afraid I don't have the time to work on it personally.

@Ailrun
Copy link
Collaborator Author

Ailrun commented Apr 11, 2018

That's frustrating... I try to find a way, and if I succeed, I will send a PR.

@juanjose-lopez-trustyou
Copy link

Hello! @kentcdodds Do you know if toHaveStyleRule works with pseudo selectors?
Thanks and sorry for the noise!

@michaelryancaputo
Copy link

michaelryancaputo commented Jan 7, 2021

Hello! @kentcdodds Do you know if toHaveStyleRule works with pseudo selectors?

Im having this problem, currently unable to detect styles applied when :focus is made. My understanding is that this should work.

  const TEXT = 'PLACEHOLDER';
  const { getByText } = render(
    <StyledDesktopNavigationLink>{TEXT}</StyledDesktopNavigationLink>,
  );

  getByText(TEXT).focus();
  expect(getByText(TEXT)).toHaveStyle(`color: ${EMPHASIS_FILL}`);

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

4 participants