From 723cbe557776ee08f261abf22d8c4d9058671500 Mon Sep 17 00:00:00 2001 From: enmanuelduran Date: Sat, 14 Sep 2024 18:55:28 +0100 Subject: [PATCH 1/8] docs: add note for throwSuggestions issue #1306 --- .../dom-testing-library/api-configuration.mdx | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/dom-testing-library/api-configuration.mdx b/docs/dom-testing-library/api-configuration.mdx index d1dd72ca4..1aee6f81b 100644 --- a/docs/dom-testing-library/api-configuration.mdx +++ b/docs/dom-testing-library/api-configuration.mdx @@ -130,6 +130,34 @@ option. screen.getByTestId('foo', {suggest: false}) // will not throw a suggestion ``` +> **Note** +> +> When this option is enabled, the library may provide suggestions that lack an +> intuitive implementation. This typically occurs for +> [roles which can not 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 an object as the +> second 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 and suppress the error, see +> [#1306](https://github.com/testing-library/dom-testing-library/issues/1306) +> and the example below: +> +> ```js +> getByRole('paragraph', { +> name: (_, element) => element.textContent === 'Hello world!', +> }) +> ``` + ### `testIdAttribute` The attribute used by [`getByTestId`](queries/bytestid.mdx) and related queries. @@ -144,4 +172,4 @@ message and container object as arguments. ### `asyncUtilTimeout` The global timeout value in milliseconds used by `waitFor` utilities. Defaults -to 1000ms. +to 1000ms. \ No newline at end of file From fea2e602dc3010e902f6a9da850ff0a615ed5350 Mon Sep 17 00:00:00 2001 From: enmanuelduran Date: Sat, 14 Sep 2024 19:16:31 +0100 Subject: [PATCH 2/8] docs: issue 1306, improve consistency --- docs/dom-testing-library/api-configuration.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/dom-testing-library/api-configuration.mdx b/docs/dom-testing-library/api-configuration.mdx index 1aee6f81b..34838a712 100644 --- a/docs/dom-testing-library/api-configuration.mdx +++ b/docs/dom-testing-library/api-configuration.mdx @@ -133,7 +133,7 @@ screen.getByTestId('foo', {suggest: false}) // will not throw a suggestion > **Note** > > When this option is enabled, the library may provide suggestions that lack an -> intuitive implementation. This typically occurs for +> intuitive implementation, this typically occurs for > [roles which can not 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: @@ -154,7 +154,7 @@ screen.getByTestId('foo', {suggest: false}) // will not throw a suggestion > > ```js > getByRole('paragraph', { -> name: (_, element) => element.textContent === 'Hello world!', +> name: (_, element) => element.textContent === 'Hello world', > }) > ``` From 24f47852a8c361d1b6e8cd6d26bdc413888534f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enmanuel=20Dur=C3=A1n?= Date: Wed, 25 Sep 2024 20:43:14 +0100 Subject: [PATCH 3/8] Update docs/dom-testing-library/api-configuration.mdx Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> --- docs/dom-testing-library/api-configuration.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dom-testing-library/api-configuration.mdx b/docs/dom-testing-library/api-configuration.mdx index 34838a712..5c98e7287 100644 --- a/docs/dom-testing-library/api-configuration.mdx +++ b/docs/dom-testing-library/api-configuration.mdx @@ -130,7 +130,7 @@ option. screen.getByTestId('foo', {suggest: false}) // will not throw a suggestion ``` -> **Note** +> :::note > > When this option is enabled, the library may provide suggestions that lack an > intuitive implementation, this typically occurs for From cc3dfed3436c9bbd844f706fb9ffce9fd151cd6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enmanuel=20Dur=C3=A1n?= Date: Wed, 25 Sep 2024 20:53:18 +0100 Subject: [PATCH 4/8] Improving formatting of the note. --- .../dom-testing-library/api-configuration.mdx | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/docs/dom-testing-library/api-configuration.mdx b/docs/dom-testing-library/api-configuration.mdx index 5c98e7287..853d1811a 100644 --- a/docs/dom-testing-library/api-configuration.mdx +++ b/docs/dom-testing-library/api-configuration.mdx @@ -130,33 +130,33 @@ option. screen.getByTestId('foo', {suggest: false}) // will not throw a suggestion ``` -> :::note -> -> When this option is enabled, the library may provide suggestions that lack an -> intuitive implementation, this typically occurs for -> [roles which can not 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 an object as the -> second 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 and suppress the error, see -> [#1306](https://github.com/testing-library/dom-testing-library/issues/1306) -> and the example below: -> -> ```js -> getByRole('paragraph', { -> name: (_, element) => element.textContent === 'Hello world', -> }) -> ``` +:::note + +When this option is enabled, the library may provide suggestions that lack an +intuitive implementation, this typically occurs for +[roles which can not 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 an object as the +second 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 and suppress the error, see +[#1306](https://github.com/testing-library/dom-testing-library/issues/1306) +and the example below: + +```js +getByRole('paragraph', { + name: (_, element) => element.textContent === 'Hello world', +}) +``` ### `testIdAttribute` @@ -172,4 +172,4 @@ message and container object as arguments. ### `asyncUtilTimeout` The global timeout value in milliseconds used by `waitFor` utilities. Defaults -to 1000ms. \ No newline at end of file +to 1000ms. From 34d1740eb2655bd12d73ab51392993cfac75dc50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enmanuel=20Dur=C3=A1n?= Date: Wed, 25 Sep 2024 20:56:49 +0100 Subject: [PATCH 5/8] Adds missing add motion syntax --- docs/dom-testing-library/api-configuration.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/dom-testing-library/api-configuration.mdx b/docs/dom-testing-library/api-configuration.mdx index 853d1811a..b96818aeb 100644 --- a/docs/dom-testing-library/api-configuration.mdx +++ b/docs/dom-testing-library/api-configuration.mdx @@ -158,6 +158,8 @@ getByRole('paragraph', { }) ``` +::: + ### `testIdAttribute` The attribute used by [`getByTestId`](queries/bytestid.mdx) and related queries. From 3b58ecdbfc72fa0c530cece046ee1e4a216d9d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enmanuel=20Dur=C3=A1n?= Date: Fri, 27 Sep 2024 19:30:07 +0100 Subject: [PATCH 6/8] Update docs/dom-testing-library/api-configuration.mdx Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> --- docs/dom-testing-library/api-configuration.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/dom-testing-library/api-configuration.mdx b/docs/dom-testing-library/api-configuration.mdx index b96818aeb..afc1d4df3 100644 --- a/docs/dom-testing-library/api-configuration.mdx +++ b/docs/dom-testing-library/api-configuration.mdx @@ -132,9 +132,9 @@ screen.getByTestId('foo', {suggest: false}) // will not throw a suggestion :::note -When this option is enabled, the library may provide suggestions that lack an -intuitive implementation, this typically occurs for -[roles which can not be named](https://w3c.github.io/aria/#namefromprohibited), +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: From b3e0db7ab1b47648f7125c671166ffb356ffdcb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enmanuel=20Dur=C3=A1n?= Date: Fri, 27 Sep 2024 19:30:19 +0100 Subject: [PATCH 7/8] Update docs/dom-testing-library/api-configuration.mdx Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> --- docs/dom-testing-library/api-configuration.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/dom-testing-library/api-configuration.mdx b/docs/dom-testing-library/api-configuration.mdx index afc1d4df3..bf375b995 100644 --- a/docs/dom-testing-library/api-configuration.mdx +++ b/docs/dom-testing-library/api-configuration.mdx @@ -143,8 +143,7 @@ TestingLibraryElementError: A better query is available, try this: getByRole('paragraph') ``` -However, there is no direct way to query paragraphs using an object as the -second parameter, such as in +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 From e7f0f3f3b4cdf94df98d709bba1dfd89a153d97f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enmanuel=20Dur=C3=A1n?= Date: Fri, 27 Sep 2024 19:30:51 +0100 Subject: [PATCH 8/8] Update docs/dom-testing-library/api-configuration.mdx Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> --- docs/dom-testing-library/api-configuration.mdx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/dom-testing-library/api-configuration.mdx b/docs/dom-testing-library/api-configuration.mdx index bf375b995..6f49e9709 100644 --- a/docs/dom-testing-library/api-configuration.mdx +++ b/docs/dom-testing-library/api-configuration.mdx @@ -147,9 +147,8 @@ However, there is no direct way to query paragraphs using the config object para `getByRole('paragraph', { name: 'Hello World' })`. To address this issue, you can leverage a custom function to validate the -element's structure and suppress the error, see -[#1306](https://github.com/testing-library/dom-testing-library/issues/1306) -and the example below: +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', {