Closed gavrielrh closed 5 months ago
Hi @gavrielrh did you manage to find a workaround for this? I've tried migrating to Happy DOM, which seems to solve this problem, but introduces other issues.
This is not a jest-dom issue. jest-dom is in charge of the jest custom matchers. That is, the things that come after expect()
, as in expect(…).toBeDisabled()
, where we provide the toBeDisabled
.
The code you show is not even using jest-dom features. It is, however, using getByRole
, which is a dom-testing-library feature.
I'm moving this issue to that repo instead.
@gavrielrh FYI, I found that anything with an escaped colon in it, followed by has
will cause this issue, e.g. .foo\:foo:has(.foo) {}
AFAIU, this is related to your testing environment. JSDOM
uses nwsapi
so this isn't something we're parsing.
I see this issue https://github.com/dperini/nwsapi/issues/111 was resolved lately and looks quite related.
I recommend either overriding the nwsapi
that JSDOM
are using or opening an issue in JSDOM to upgrade the version.
I'm resolving this one as there's nothing we can actively do to help here.
Please feel free to comment here if you believe this is related to testing-library.
@testing-library/jest-dom
version: 6.2.0node
version: 20.11.0jest
version: 29.7.0yarn
version: 1.22.19Relevant code or config:
What you did:
Wrote a test for a component that uses a specific CSS selector in emotionStyled. The CSS is applying properly to the component outside of the test. Ran the test.
What happened:
Reproduction:
Codesandbox: https://codesandbox.io/p/devbox/eager-leaf-fk2n4y?file=%2Fsrc%2Findex.test.tsx%3A11%2C1
Problem description:
It appears that an underlying library (nwsapi?) used by @testing-library fails to parse the :has() pseudo-class selector if it is prefixed with an attribute selector. This bubbles up as a syntax error when running the test.
The syntax error is not very helpful:
and the error itself means it is impossible to test components using emotion styled that rely on this selector.
Suggested solution:
Assuming the issue is with nwsapi, updating how it parses the :has() selector to account for the possibility of a attribute selector prefix, would fix this. I don't know enough about testing-library/dom -> jsdom -> nwsapi to feel confident that this is the correct solution though.