From 5c414e1524f279b586bcc9be0af1008a6b38c902 Mon Sep 17 00:00:00 2001 From: Vesa Laakso Date: Thu, 14 Feb 2019 10:43:21 +0200 Subject: [PATCH 1/3] Add test for queryAllByText with document as container --- src/__tests__/element-queries.js | 9 +++++++++ 1 file changed, 9 insertions(+) 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`) From d1f0fc3144522a444cf891e1b3c11d5d4945a640 Mon Sep 17 00:00:00 2001 From: Vesa Laakso Date: Thu, 14 Feb 2019 10:48:00 +0200 Subject: [PATCH 2/3] Fix queryAllByText not allowing document to be the container --- src/queries.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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)) From 92b27118224d286cf0b0926816e795d4cc6bb10d Mon Sep 17 00:00:00 2001 From: Vesa Laakso Date: Thu, 14 Feb 2019 10:49:02 +0200 Subject: [PATCH 3/3] Added myself to all contributors --- .all-contributorsrc | 10 ++++++++++ README.md | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) 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] -[![All Contributors](https://img.shields.io/badge/all_contributors-49-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-50-orange.svg?style=flat-square)](#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
dadamssg](https://github.com/dadamssg)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=dadamssg "Code") | [Neil Kistner
Neil Kistner](https://neilkistner.com/)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=wyze "Code") | [Ben Chauvette
Ben Chauvette](http://bdchauvette.net/)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=bdchauvette "Code") | [Jeff Baumgardt
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
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
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
Tamas Fodor](https://github.com/ruffle1986)
[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=ruffle1986 "Documentation") | | [Benjamin Eckardt
Benjamin Eckardt](https://github.com/BenjaminEckardt)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=BenjaminEckardt "Code") | [Ryan Campbell
Ryan Campbell](https://github.com/campbellr)
[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=campbellr "Documentation") | [Taylor Briggs
Taylor Briggs](https://taylor-briggs.com)
[⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=TaylorBriggs "Tests") | [John Gozde
John Gozde](https://github.com/jgoz)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jgoz "Code") | [C. T. Lin
C. T. Lin](https://github.com/chentsulin)
[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=chentsulin "Documentation") | [Terrence Wong
Terrence Wong](http://terrencewwong.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=terrencewwong "Code") | [Soo Jae Hwang
Soo Jae Hwang](https://www.ossfinder.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=misoguy "Code") | | [Royston Shufflebotham
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
Vadim Brodsky](http://www.vadimbrodsky.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=VadimBrodsky "Code") | [Eunjae Lee
Eunjae Lee](https://twitter.com/eunjae_lee)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=eunjae-lee "Code") | [David Peter
David Peter](http://davidpeter.me)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=sarenji "Code") | [Shy Alter
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
Łukasz Makuch](https://lukaszmakuch.pl)
[📦](#platform-lukaszmakuch "Packaging/porting to new platform") | [Tyler Haas
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
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.