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

toHaveStyleRule errors if component is empty #189

Closed
guyfedwards opened this issue Sep 14, 2018 · 7 comments
Closed

toHaveStyleRule errors if component is empty #189

guyfedwards opened this issue Sep 14, 2018 · 7 comments
Labels

Comments

@guyfedwards
Copy link

When the component that has .toHaveStyleRule call on it, it errors. As you can see below, expect(wrapper.find('Input__ValidationMessage').length).toBe(1) passes.
image

Adding some child text to the component causes the test to pass.
image

@MicheleBertoli
Copy link
Member

Thank you very much for opening this issue, @guyfedwards.
Do you mind sharing your component and test so that I can repro?

@guyfedwards
Copy link
Author

guyfedwards commented Sep 17, 2018

Sure @MicheleBertoli, you can find the component here and the test here. You can see the second to last test case is the culprit, with a comment referencing this issue.

If you want to clone the repo, the relevant branch is react-16.5-enzyme

@MicheleBertoli
Copy link
Member

Hello @guyfedwards, I saw that weaveworks/ui-components#379 was merged.
Can we close this, or does the issue still persist?

@guyfedwards
Copy link
Author

guyfedwards commented Sep 17, 2018

Oh sorry, I probably deleted the branch 🤦‍♂️ The issue still persists and you can see on master component & test

Thanks @MicheleBertoli

@MicheleBertoli
Copy link
Member

Thanks for providing more information, @guyfedwards.
Unless I'm missing something, the test is passing on master, right?
(I cloned the repo and it seems to work as expected)

In any case, my recommendation is to set the displayName, like:

ValidationMessage.displayName = 'ValidationMessage'

And then:

expect(wrapper.find('ValidationMessage')).toHaveStyleRule(
  'visibility',
  'visible'
);

@guyfedwards
Copy link
Author

guyfedwards commented Sep 22, 2018

@MicheleBertoli The test passes as I have added the following lines to make it pass:

      // https://github.com/styled-components/jest-styled-components/issues/189
      message: 'Derp!',

That comment referencing this issue as the reason for the content being set.
If you remove the message, thus setting the content to be empty, then the test fails.

Apologies for not being clearer.

MicheleBertoli added a commit that referenced this issue Sep 22, 2018
@MicheleBertoli
Copy link
Member

Yay! Found the issue, and fixed it.
Please install v6.2.1.
Thank you very much, @guyfedwards.

guyfedwards added a commit to weaveworks/ui-components that referenced this issue Sep 24, 2018
no need to pass message now just to satisfy issue in upstream lib
jest-styled-components

upstream issue: styled-components/jest-styled-components#189
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants