File tree 1 file changed +28
-0
lines changed 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,34 @@ option.
130
130
screen .getByTestId (' foo' , {suggest: false }) // will not throw a suggestion
131
131
```
132
132
133
+ :::note
134
+
135
+ When this option is enabled, it may provide suggestions that lack an
136
+ intuitive implementation. Typically this happens for
137
+ [ roles which cannot be named] ( https://w3c.github.io/aria/#namefromprohibited ) ,
138
+ most notably paragraphs. For instance, if you attempt to use
139
+ [ ` getByText ` ] ( queries/bytext.mdx ) , you may encounter the following error:
140
+
141
+ ```
142
+ TestingLibraryElementError: A better query is available, try this:
143
+ getByRole('paragraph')
144
+ ```
145
+
146
+ However, there is no direct way to query paragraphs using the config object parameter, such as in
147
+ ` getByRole('paragraph', { name: 'Hello World' }) ` .
148
+
149
+ To address this issue, you can leverage a custom function to validate the
150
+ element's structure, as shown in the example below.
151
+ More information can be found in the [ GitHub issue] ( https://github.com/testing-library/dom-testing-library/issues/1306 )
152
+
153
+ ``` js
154
+ getByRole (' paragraph' , {
155
+ name : (_ , element ) => element .textContent === ' Hello world' ,
156
+ })
157
+ ```
158
+
159
+ :::
160
+
133
161
### ` testIdAttribute `
134
162
135
163
The attribute used by [ ` getByTestId ` ] ( queries/bytestid.mdx ) and related queries.
You can’t perform that action at this time.
0 commit comments