-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Breaks toHaveStyle assertions in v5.2.0 #3297
Comments
Same problem here (I raised the issue at I fixed it temporarily by downgrading to |
This problem also occurs in tests using getComputedStyle(). As @barucAlmaguer I fixed it by downgrading to |
So it seems that
which made tests un-runnable, but this was fixed in |
styled-components v5.2.0 has issues with retrieving styles: styled-components/styled-components#3297 ... J Seitz advised removing these tests
See also the discussion thread here: #3262 |
v5.2.1 fixed it for me. |
v5.2.0 causes this problem but v5.2.1 does not. |
For some reason 5.2.1 doesn't work for me either, I'll just skip this tests for now, I'll wait for next versions. |
Same it does not work for me on 5.2.1 |
As of I can only assume it's because Based on @probablyup's comment here
I just added a console log to my Jest config and it says it does exist: console.log('HTMLElement in window: ', 'HTMLElement' in window);
=> HTMLElement in window: true I assume this is unwanted behaviour? |
Unfortunately, same issue with |
Sorry, I'll have to close this for now due to inactivity. I'm pretty sure this related to https://github.com/styled-components/jest-styled-components, right? In general, this is also an issue that's unrelated to the codebase in this repository itself, so there's not really any way forward to resolve this. In other words, no change in this repository has any chance of resolving this, as it's unrelated, which makes this issue open-ended potentially. |
We're seeing this as well, and it seems unrelated to expect(getByTitle('Close drawer')).toBeVisible(); Passes in |
Sill i am facing the same issue in the version of "@testing-library/jest-dom": "^5.16.1". |
I see this issue starting with v5.3.0. Note that I have this also in 5.3.0, so it seems to be different then #3570. |
6.0.0-rc.1 — the same issue. |
I wan't to add an update regarding the cause of the problem and a possible workaround. Styled-components uses multiple NPM entry points: https://github.com/styled-components/styled-components/blob/v5.3.10/packages/styled-components/package.json#L5 The default CommonJS entry point ( A possible work around involves creating a Jest resolver (https://jestjs.io/docs/configuration#resolver-string) that points to the browser entry point in the Essentially, this workaround is similar to the one described in this link: #3570 (comment), but instead of using a mock, it utilizes the resolver feature. I don't know what the solution should be from the styled-components side. While I understand that they intend to build the package in a way that the default export consumed by NodeJS assumes SSR, this decision also affects the DX of people using Jest+JSDOM, which is a common testing environment in React. Ideally, the package should be exported differently to ensure it works out of the box. However, if that's not an option, providing documentation and an official Jest resolver would help. Additionally, I haven't tried using pure-ESM (using Jest's experimental ESM support), so I don't know if the problem persists with that setup. @kitten I don't know why this issue is closed, as the problem still exists today. |
Will look into this shortly for v6, if the fix can be easily backported to v5 will do so |
@probablyup Any news on this? Trying to upgrade to v6 now but it's causing all my |
I found out that replacing the |
Is this where we come to cry about update to v6 styled-components breaking our tests? I've updated from +1 for updates on the resolution |
I have used styled-components@6.0.1 so expect(container.querySelector('div')).toHaveStyle( can anyone suggest whats required for that then it's working newer version of style component. |
It seems that updating to |
Can confirm- works! I'm on v5.3.0 |
Environment
Reproduction
Steps to reproduce
Install v5.2.0 and try to test a React component that renders a StyledComponent with
.toHaveStyle()
from@testing-library/jest-dom/extend-expect
.e.g.:
Expected Behavior
Asserts element has style rule.
Actual Behavior
Always fail.
Notes
I upgraded all dependencies today and a lot of tests broke.
I first went to
jest-dom
repository and found a similar issue (testing-library/jest-dom#295 (comment)) but after upgrading dependency by dependency I noticed it's actually only when I upgradestyled-components
tov5.2.0
that it starts to fail.The text was updated successfully, but these errors were encountered: