-
Notifications
You must be signed in to change notification settings - Fork 392
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
HtmlElementTypeError for custom jsdom instance #58
Comments
Also, why I do it? Among others here's the quote for jsdom readme:
|
Can you provide a small repo where others can reproduce the problem? Also, even better, if you can provide the fix yourself, attempting what you suggest in the suggested solution section, that'd be great. Thanks! |
Here you go...
And execute following const { JSDOM } = require('jsdom')
const { toHaveTextContent } = require('jest-dom')
const { window } = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
console.log(window.document.body instanceof window.HTMLElement)
toHaveTextContent(window.document.body, 'Hello world') |
I don't want to suggest any fix, I just think it should work with this method of using |
Sorry for the delayed response. I'm not familiar with using custom jsdom instances. So I do not feel comfortable fixing it myself. It seems you have some suggested solutions in your original issue report above. Maybe you can contribute a fix yourself? |
🎉 This issue has been resolved in version 2.0.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
jest-dom
version: 1.11.0node
version: 10.4.1npm
(oryarn
) version: yarn 1.7.0Relevant code or config:
next.render is a helper I've created that returns custom jsdom instance
What you did:
Tried to use toHaveTextContent matcher with custom jsdom instance
What happened:
Error is thrown:
Reproduction:
As above
Problem description:
Problem description:
It seems you throw HtmlElementTypeError with
htmlElement instanceof HTMLElement
but the element that I pass has separate of HTMLElement created along separate window object.See:
Suggested solution:
constructor.name
,__proto__.constructor.name
,__proto__.__proto__.constructor.name
etc. instead ofinstanceof
?The text was updated successfully, but these errors were encountered: