Element.matches fails when using non-matching descendant selector on element attached to document
See original GitHub issueconst element = document.createElement('div');
document.appendChild(element);
expect(element.matches('.nonexistent-class div')).toBe(false);
TypeError: Cannot read properties of undefined (reading 'split')
296 | ): { priorityWeight: number; matches: boolean } {
297 | const regexp = new RegExp(CLASS_REGEXP, 'g');
> 298 | const classList = element.className.split(' ');
| ^
299 | const classSelector = selector.split(':')[0];
300 | let priorityWeight = 0;
301 | let match: RegExpMatchArray;
at SelectorItem.matchesClass (src/query-selector/SelectorItem.ts:298:39)
at SelectorItem.match (src/query-selector/SelectorItem.ts:91:24)
at Function.matchesSelector (src/query-selector/QuerySelector.ts:107:27)
at Function.matchesSelector (src/query-selector/QuerySelector.ts:113:15)
at Function.matchesSelector (src/query-selector/QuerySelector.ts:113:15)
at Function.matchesSelector (src/query-selector/QuerySelector.ts:113:15)
at Function.match (src/query-selector/QuerySelector.ts:66:24)
at HTMLElement.matches (src/nodes/element/Element.ts:734:24)
Issue Analytics
- State:
- Created a year ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Element.matches() - Web APIs - MDN Web Docs
The matches() method of the Element interface tests whether the element would be selected by the specified CSS selector.
Read more >Why does jQuery or a DOM method such as getElementById ...
For efficiency, select the nearest reliable ancestor of the target element rather than attaching it to the document .
Read more >Selectors Level 3 - W3C
Selectors are patterns that match against elements in a tree, and as such form one of several technologies that can be used to...
Read more >Searching: getElement*, querySelector*
If an element has the id attribute, we can get the element using the method document.getElementById(id) , no matter where it is.
Read more >Select Page Elements | Basic Guides - TestCafe
Finds a descendant node that matches the specified CSS selector or predicate. Selects parent elements. Selects child elements.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s fixed! Everything looks nice, thanks!
Thanks for your contribution @IGx89! 🙂
Your fix is in now.
You can read more about the release here: https://github.com/capricorn86/happy-dom/releases/tag/v7.5.14