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

Matchers (except toHaveTextContent) should support any Element #313

Open
nickmccurdy opened this issue Nov 30, 2020 · 2 comments
Open

Matchers (except toHaveTextContent) should support any Element #313

nickmccurdy opened this issue Nov 30, 2020 · 2 comments

Comments

@nickmccurdy
Copy link
Member

Relevant code or config:

expect(svgElement).toBeVisible();

What happened:

received value must be an HTMLElement or an SVGElement.

Problem description:

Several Testing Libraries are having their TypeScript types updated to take Element rather than HTMLElement as arguments so other element types like SVGElement are allowed. However, Jest DOM performs runtime checks against HTMLElement and SVGElement, so that any other element type would fail.

Suggested solution:

We should update our typechecking to check instanceof Element for consistency with #306 and testing-library/react-testing-library#833.

@chrisfosterelli
Copy link

chrisfosterelli commented Jun 11, 2021

Any ideas on a workaround for this currently? We have some HTMLSpanElements that appear to fail a .toBeInTheDocument check as a result

This one is kind of interesting because our code isn't actually using typescript, I suspect this is coming from an underlying library we are making use of.

EDIT: We ended up just using toBeTruthy() and leaving a comment with a link to this issue

@chrisfosterelli
Copy link

chrisfosterelli commented Jun 11, 2021

Hm, actually it's possible that my issue is something else entirely. My objects seem to be instances of HTMLElement but not instances of ownerDocument.defaultView.HTMLElement, which is what the helper is actually checking. This code involves some multi-document stuff, my issue is possibly not this issue, so I'll have to keep looking 👀 Sorry for the noise!

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

2 participants