dom-testing-library: getByText throws node.matches is not a function

I have the following test:

getByText(fixture.nativeElement, text);

I get the error:

node.matches is not a function

After debugging, I found that the problem is in the following line:

 return Array.from([...baseArray, ...container.querySelectorAll(selector)])
    .filter(node => !ignore || !node.matches(ignore))
    .filter(node => matcher(getNodeText(node), node, text, matchNormalizer))

One of the nodes is a NodeList, and therefore we get the error.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 39 (23 by maintainers)

Most upvoted comments

๐ŸŽ‰ This issue has been resolved in version 3.16.8 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

Why donโ€™t we just change it to:

[...baseArray, ...Array.from(container.querySelectorAll(selector))]

?

Yes, itโ€™s Angular, but itโ€™s a standard DOM element.

Will be fixed by https://github.com/kentcdodds/dom-testing-library/pull/213

EDIT: Maybe? Waiting confirmation for that.

EDIT2: No, will not be fixed by #213. This is likely caused by #109 way further down in history where the node.matches line was first added