Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add note for throwSuggestions issue #1306 #1425

Merged
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