diff --git a/.all-contributorsrc b/.all-contributorsrc index 4be0f890..28233baa 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -267,6 +267,15 @@ "contributions": [ "code" ] + }, + { + "login": "rubencosta", + "name": "Ruben Costa", + "avatar_url": "https://avatars3.githubusercontent.com/u/577921?v=4", + "profile": "http://nuances.co", + "contributions": [ + "code" + ] } ] } diff --git a/README.md b/README.md index e77f9176..a307e24a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ [![downloads][downloads-badge]][npmtrends] [![MIT License][license-badge]][license] -[![All Contributors](https://img.shields.io/badge/all_contributors-26-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-27-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc] @@ -873,7 +873,8 @@ Thanks goes to these people ([emoji key][emojis]): | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | [
Anto Aravinth](https://github.com/antoaravinth)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Tests") [πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Documentation") | [
Jonah Moses](https://github.com/JonahMoses)
[πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=JonahMoses "Documentation") | [
Łukasz Gandecki](http://team.thebrain.pro)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Tests") [πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Documentation") | [
Ivan Babak](https://sompylasar.github.io)
[πŸ›](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Asompylasar "Bug reports") [πŸ€”](#ideas-sompylasar "Ideas, Planning, & Feedback") [πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=sompylasar "Code") [πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=sompylasar "Documentation") | [
Jesse Day](https://github.com/jday3)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=jday3 "Code") | [
Ernesto GarcΓ­a](http://gnapse.github.io)
[πŸ’¬](#question-gnapse "Answering Questions") [πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=gnapse "Code") [πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=gnapse "Documentation") | [
Josef Maxx Blake](http://jomaxx.com)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Code") [πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Tests") | | [
Alex Cook](https://github.com/alecook)
[πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=alecook "Documentation") [πŸ’‘](#example-alecook "Examples") | [
Daniel Cook](https://github.com/dfcook)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Code") [πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Tests") | [
Thomas Chia](https://github.com/thchia)
[πŸ›](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Athchia "Bug reports") [πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=thchia "Code") | [
Tim Deschryver](https://github.com/tdeschryver)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Tests") | [
Alex Krolick](https://alexkrolick.com)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=alexkrolick "Code") | [
Maddi Joyce](http://www.maddijoyce.com)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=maddijoyce "Code") | [
Peter Kamps](https://github.com/npeterkamps)
[πŸ›](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Anpeterkamps "Bug reports") [πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=npeterkamps "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=npeterkamps "Tests") | -| [
Jonathan Stoye](http://jonathanstoye.de)
[πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=JonathanStoye "Documentation") | [
Sanghyeon Lee](https://github.com/yongdamsh)
[πŸ’‘](#example-yongdamsh "Examples") | [
Justice Mba ](https://github.com/Dajust)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=Dajust "Code") [πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=Dajust "Documentation") [πŸ€”](#ideas-Dajust "Ideas, Planning, & Feedback") | [
Wayne Crouch](https://github.com/wgcrouch)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=wgcrouch "Code") | [
Ben Elliott](http://benjaminelliott.co.uk)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=benelliott "Code") | +| [
Jonathan Stoye](http://jonathanstoye.de)
[πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=JonathanStoye "Documentation") | [
Sanghyeon Lee](https://github.com/yongdamsh)
[πŸ’‘](#example-yongdamsh "Examples") | [
Justice Mba ](https://github.com/Dajust)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=Dajust "Code") [πŸ“–](https://github.com/kentcdodds/dom-testing-library/commits?author=Dajust "Documentation") [πŸ€”](#ideas-Dajust "Ideas, Planning, & Feedback") | [
Wayne Crouch](https://github.com/wgcrouch)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=wgcrouch "Code") | [
Ben Elliott](http://benjaminelliott.co.uk)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=benelliott "Code") | [
Ruben Costa](http://nuances.co)
[πŸ’»](https://github.com/kentcdodds/dom-testing-library/commits?author=rubencosta "Code") | + This project follows the [all-contributors][all-contributors] specification. diff --git a/src/__tests__/element-queries.js b/src/__tests__/element-queries.js index c6f3e840..d36209f8 100644 --- a/src/__tests__/element-queries.js +++ b/src/__tests__/element-queries.js @@ -2,8 +2,8 @@ import 'jest-dom/extend-expect' import {render} from './helpers/test-utils' beforeEach(() => { - window.Cypress = null; -}); + window.Cypress = null +}) test('query can return null', () => { const { @@ -82,12 +82,20 @@ test('get can get form controls by label text', () => { +
+
+ + + +
`) expect(getByLabelText('1st').id).toBe('first-id') expect(getByLabelText('2nd').id).toBe('second-id') expect(getByLabelText('3rd').id).toBe('third-id') expect(getByLabelText('4th').id).toBe('fourth.id') + expect(getByLabelText('5th one').id).toBe('fifth-id') + expect(getByLabelText('5th two').id).toBe('fifth-id') }) test('get can get form controls by placeholder', () => { @@ -174,15 +182,15 @@ test('getAll* matchers return an array', () => {
finding nemo poster finding dory poster jumanji poster

Where to next?

diff --git a/src/queries.js b/src/queries.js index 6ea1a20e..3795efa0 100644 --- a/src/queries.js +++ b/src/queries.js @@ -3,9 +3,9 @@ import {getNodeText} from './get-node-text' import {prettyDOM} from './pretty-dom' function debugDOM(htmlElement) { - const limit = process.env.DEBUG_PRINT_LIMIT || 7000 - const inNode = (typeof module !== 'undefined' && module.exports) - const inCypress = (typeof window !== 'undefined' && window.Cypress) + const limit = process.env.DEBUG_PRINT_LIMIT || 7000 + const inNode = typeof module !== 'undefined' && module.exports + const inCypress = typeof window !== 'undefined' && window.Cypress /* istanbul ignore else */ if (inCypress) { return '' @@ -66,7 +66,7 @@ function queryAllByLabelText( if (label.getAttribute('id')) { // return container.querySelector( - `[aria-labelledby="${label.getAttribute('id')}"]`, + `[aria-labelledby~="${label.getAttribute('id')}"]`, ) } if (label.childNodes.length) { @@ -155,7 +155,10 @@ function queryByAltText(...args) { function getAllByTestId(container, id, ...rest) { const els = queryAllByTestId(container, id, ...rest) if (!els.length) { - throw getElementError(`Unable to find an element by: [data-testid="${id}"]`, container) + throw getElementError( + `Unable to find an element by: [data-testid="${id}"]`, + container, + ) } return els } @@ -167,7 +170,10 @@ function getByTestId(...args) { function getAllByTitle(container, title, ...rest) { const els = queryAllByTitle(container, title, ...rest) if (!els.length) { - throw getElementError(`Unable to find an element with the title: ${title}.`, container) + throw getElementError( + `Unable to find an element with the title: ${title}.`, + container, + ) } return els } @@ -179,7 +185,10 @@ function getByTitle(...args) { function getAllByValue(container, value, ...rest) { const els = queryAllByValue(container, value, ...rest) if (!els.length) { - throw getElementError(`Unable to find an element with the value: ${value}.`, container) + throw getElementError( + `Unable to find an element with the value: ${value}.`, + container, + ) } return els } @@ -191,7 +200,10 @@ function getByValue(...args) { function getAllByPlaceholderText(container, text, ...rest) { const els = queryAllByPlaceholderText(container, text, ...rest) if (!els.length) { - throw getElementError(`Unable to find an element with the placeholder text of: ${text}`, container) + throw getElementError( + `Unable to find an element with the placeholder text of: ${text}`, + container, + ) } return els } @@ -205,9 +217,15 @@ function getAllByLabelText(container, text, ...rest) { if (!els.length) { const labels = queryAllLabelsByText(container, text, ...rest) if (labels.length) { - throw getElementError(`Found a label with the text of: ${text}, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.`, container) + throw getElementError( + `Found a label with the text of: ${text}, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.`, + container, + ) } else { - throw getElementError(`Unable to find a label with the text of: ${text}`, container) + throw getElementError( + `Unable to find a label with the text of: ${text}`, + container, + ) } } return els @@ -220,7 +238,10 @@ function getByLabelText(...args) { function getAllByText(container, text, ...rest) { const els = queryAllByText(container, text, ...rest) if (!els.length) { - throw getElementError(`Unable to find an element with the text: ${text}. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.`, container) + throw getElementError( + `Unable to find an element with the text: ${text}. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.`, + container, + ) } return els } @@ -232,7 +253,10 @@ function getByText(...args) { function getAllByAltText(container, alt, ...rest) { const els = queryAllByAltText(container, alt, ...rest) if (!els.length) { - throw getElementError(`Unable to find an element with the alt text: ${alt}`, container) + throw getElementError( + `Unable to find an element with the alt text: ${alt}`, + container, + ) } return els }