Skip to content

Commit

Permalink
docs: add note for throwSuggestions issue #1306 (#1425)
Browse files Browse the repository at this point in the history
* 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 <28659384+timdeschryver@users.noreply.github.com>

* Improving formatting of the note.

* Adds missing add motion syntax

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

Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>

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

Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>

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

Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>

---------

Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
  • Loading branch information
enmanuelduran and timdeschryver authored Sep 28, 2024
1 parent f302be9 commit 03b1695
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/dom-testing-library/api-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,34 @@ option.
screen.getByTestId('foo', {suggest: false}) // will not throw a suggestion
```

:::note

When this option is enabled, it may provide suggestions that lack an
intuitive implementation. Typically this happens for
[roles which cannot be named](https://w3c.github.io/aria/#namefromprohibited),
most notably paragraphs. For instance, if you attempt to use
[`getByText`](queries/bytext.mdx), you may encounter the following error:

```
TestingLibraryElementError: A better query is available, try this:
getByRole('paragraph')
```

However, there is no direct way to query paragraphs using the config object parameter, such as in
`getByRole('paragraph', { name: 'Hello World' })`.

To address this issue, you can leverage a custom function to validate the
element's structure, as shown in the example below.
More information can be found in the [GitHub issue](https://github.com/testing-library/dom-testing-library/issues/1306)

```js
getByRole('paragraph', {
name: (_, element) => element.textContent === 'Hello world',
})
```

:::

### `testIdAttribute`

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

0 comments on commit 03b1695

Please sign in to comment.