@@ -15,7 +15,7 @@ function queryLabelByText(container, text) {
1515function queryByLabelText ( container , text , { selector = '*' } = { } ) {
1616 const label = queryLabelByText ( container , text )
1717 if ( ! label ) {
18- return null
18+ return queryByAttribute ( 'aria-label' , container , text )
1919 }
2020 /* istanbul ignore if */
2121 if ( label . control ) {
@@ -46,22 +46,21 @@ function queryByText(container, text, {selector = '*'} = {}) {
4646 )
4747}
4848
49- function queryByPlaceholderText ( container , text ) {
49+ // this is just a utility and not an exposed query.
50+ // There are no plans to expose this.
51+ function queryByAttribute ( attribute , container , text ) {
5052 return (
51- Array . from ( container . querySelectorAll ( '[placeholder]' ) ) . find ( node =>
52- matches ( node . getAttribute ( 'placeholder' ) , node , text ) ,
53+ Array . from ( container . querySelectorAll ( `[ ${ attribute } ]` ) ) . find ( node =>
54+ matches ( node . getAttribute ( attribute ) , node , text ) ,
5355 ) || null
5456 )
5557}
5658
57- function queryByTestId ( container , id ) {
58- return container . querySelector ( getDataTestIdSelector ( id ) )
59- }
60-
61- function getDataTestIdSelector ( id ) {
62- return `[data-testid="${ id } "]`
63- }
59+ const queryByPlaceholderText = queryByAttribute . bind ( null , 'placeholder' )
60+ const queryByTestId = queryByAttribute . bind ( null , 'data-testid' )
6461
62+ // this is just a utility and not an exposed query.
63+ // There are no plans to expose this.
6564function getText ( node ) {
6665 return Array . from ( node . childNodes )
6766 . filter (
@@ -79,9 +78,7 @@ function getText(node) {
7978function getByTestId ( container , id , ...rest ) {
8079 const el = queryByTestId ( container , id , ...rest )
8180 if ( ! el ) {
82- throw new Error (
83- `Unable to find an element by: ${ getDataTestIdSelector ( id ) } ` ,
84- )
81+ throw new Error ( `Unable to find an element by: [data-testid="${ id } "]` )
8582 }
8683 return el
8784}
0 commit comments