diff --git a/.all-contributorsrc b/.all-contributorsrc
index 4b996c87..2c085cca 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -488,6 +488,16 @@
"code",
"test"
]
+ },
+ {
+ "login": "valscion",
+ "name": "Vesa Laakso",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/482561?v=4",
+ "profile": "http://vesalaakso.com",
+ "contributions": [
+ "code",
+ "test"
+ ]
}
]
}
diff --git a/README.md b/README.md
index 4f967bcd..27061d52 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@
[![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]
-[](#contributors)
+[](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Code of Conduct][coc-badge]][coc]
@@ -138,6 +138,8 @@ Thanks goes to these people ([emoji key][emojis]):
| [
dadamssg](https://github.com/dadamssg)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=dadamssg "Code") | [
Neil Kistner](https://neilkistner.com/)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=wyze "Code") | [
Ben Chauvette](http://bdchauvette.net/)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=bdchauvette "Code") | [
Jeff Baumgardt](https://github.com/JeffBaumgardt)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=JeffBaumgardt "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=JeffBaumgardt "Documentation") | [
Matan Kushner](http://matchai.me)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Documentation") [🤔](#ideas-matchai "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Tests") | [
Alex Wendte](http://www.wendtedesigns.com/)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Tests") | [
Tamas Fodor](https://github.com/ruffle1986)
[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=ruffle1986 "Documentation") |
| [
Benjamin Eckardt](https://github.com/BenjaminEckardt)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=BenjaminEckardt "Code") | [
Ryan Campbell](https://github.com/campbellr)
[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=campbellr "Documentation") | [
Taylor Briggs](https://taylor-briggs.com)
[⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=TaylorBriggs "Tests") | [
John Gozde](https://github.com/jgoz)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jgoz "Code") | [
C. T. Lin](https://github.com/chentsulin)
[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=chentsulin "Documentation") | [
Terrence Wong](http://terrencewwong.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=terrencewwong "Code") | [
Soo Jae Hwang](https://www.ossfinder.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=misoguy "Code") |
| [
Royston Shufflebotham](https://github.com/RoystonS)
[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3ARoystonS "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Tests") | [
Vadim Brodsky](http://www.vadimbrodsky.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=VadimBrodsky "Code") | [
Eunjae Lee](https://twitter.com/eunjae_lee)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=eunjae-lee "Code") | [
David Peter](http://davidpeter.me)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=sarenji "Code") | [
Shy Alter](https://twitter.com/@puemos)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=puemos "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=puemos "Documentation") | [
Łukasz Makuch](https://lukaszmakuch.pl)
[📦](#platform-lukaszmakuch "Packaging/porting to new platform") | [
Tyler Haas](https://github.com/tylerthehaas)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=tylerthehaas "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=tylerthehaas "Tests") |
+| [
Vesa Laakso](http://vesalaakso.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=valscion "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=valscion "Tests") |
+
This project follows the [all-contributors][all-contributors] specification.
diff --git a/src/__tests__/element-queries.js b/src/__tests__/element-queries.js
index 266c7c22..d89d9142 100644
--- a/src/__tests__/element-queries.js
+++ b/src/__tests__/element-queries.js
@@ -407,6 +407,15 @@ test('queryAllByText can query dom nodes', () => {
expect(queryAllByText('hi', {selector: 'span'})).toHaveLength(0)
})
+test('queryAllByText works with document container', () => {
+ // This is required for Cypress as it uses `document`
+ // as the container for all methods
+ const {queryAllByText} = renderIntoDocument('
hello
') + expect(queryAllByText('hello')).toHaveLength(1) + expect(queryAllByText('not here')).toHaveLength(0) + expect(queryAllByText('hello', {selector: 'span'})).toHaveLength(0) +}) + test('using jest helpers to assert element states', () => { const {queryByTestId} = render(`2`) diff --git a/src/queries.js b/src/queries.js index 15c7233c..6eaf70f2 100644 --- a/src/queries.js +++ b/src/queries.js @@ -105,7 +105,10 @@ function queryAllByText( ) { const matcher = exact ? matches : fuzzyMatches const matchNormalizer = makeNormalizer({collapseWhitespace, trim, normalizer}) - const baseArray = container.matches(selector) ? [container] : [] + let baseArray = [] + if (typeof container.matches === 'function' && container.matches(selector)) { + baseArray = [container] + } return Array.from([...baseArray, ...container.querySelectorAll(selector)]) .filter(node => !ignore || !node.matches(ignore)) .filter(node => matcher(getNodeText(node), node, text, matchNormalizer))