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

doc(queryconfig): Allows configuring a different element query mechanism #964

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/dom-testing-library/api-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,39 @@ message and container object as arguments.

The global timeout value in milliseconds used by `waitFor` utilities. Defaults
to 1000ms.

### `queryElement` & `queryAllElements`

If your application requires a specific way to query elements on the page, you
can define a custom strategy used by the testing library.

For that register your strategy once:

```js
configure({
queryElement: (element, query) => element.querySelector(query),
queryAllElements: (element, query) => element.querySelectorAll(query),
})
```

Defaults to `element.querySelector` and `element.querySelectorAll`.

The interface of the functions will take two arguments, `element` and `query`,
which the wrapper can use. The expected return value is a single element (for
`queryElement`) or a list of elements (for `queryAllElements`).

This can be used to extend queries to reach into the shadow dom or iframes. An
example using the
[query-selector-shadow-dom](https://github.com/Georgegriff/query-selector-shadow-dom)
library looks like the following:

```js
import {
querySelectorAllDeep,
querySelectorDeep,
} from 'query-selector-shadow-dom'
configure({
queryElement: querySelectorDeep,
queryAllElements: querySelectorAllDeep,
})
```