Skip to content

Commit 03b1695

Browse files
docs: add note for throwSuggestions issue #1306 (#1425)
* docs: add note for throwSuggestions issue #1306 * docs: issue 1306, improve consistency * Update docs/dom-testing-library/api-configuration.mdx Co-authored-by: Tim Deschryver <[email protected]> * Improving formatting of the note. * Adds missing add motion syntax * Update docs/dom-testing-library/api-configuration.mdx Co-authored-by: Tim Deschryver <[email protected]> * Update docs/dom-testing-library/api-configuration.mdx Co-authored-by: Tim Deschryver <[email protected]> * Update docs/dom-testing-library/api-configuration.mdx Co-authored-by: Tim Deschryver <[email protected]> --------- Co-authored-by: Tim Deschryver <[email protected]>
1 parent f302be9 commit 03b1695

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/dom-testing-library/api-configuration.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,34 @@ option.
130130
screen.getByTestId('foo', {suggest: false}) // will not throw a suggestion
131131
```
132132

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+
133161
### `testIdAttribute`
134162

135163
The attribute used by [`getByTestId`](queries/bytestid.mdx) and related queries.

0 commit comments

Comments
 (0)