From 4a83a34b25ca88f5f5cb43434e5de29ae21a54a7 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Fri, 30 Dec 2022 20:43:07 +0100 Subject: [PATCH 1/3] docs: improve findBy docs by adding information about screen.debug() --- website/docs/Queries.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/website/docs/Queries.md b/website/docs/Queries.md index 7ae87cbc3..1f31e6f49 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -64,14 +64,18 @@ title: Queries ### findAllBy -`findAllBy` queries return a promise which resolves to an array when any matching elements are found. The promise is rejected if no elements match after a default timeout of 4500ms. +`findAllBy` queries return a promise which resolves to an array of matching elements. The promise is rejected if no elements match after a default timeout of 1000 ms. :::info -In order to properly use `findBy` and `findAllBy` queries you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0). +`findBy` and `findAllBy` queries accept optional `waitForOptions` object argument which can contain `timeout`, `interval` and `onTimeout` properies which have the same meaning as respective options for [`waitFor`](api#waitfor) function. ::: :::info -`findBy` and `findAllBy` queries accept optional `waitForOptions` object argument which can contain `timeout` and `interval` properies which have the same meaning as respective options for [`waitFor`](api#waitfor) function. +In cases when your `findBy` and `findAllBy` queries throw when not able to find matching elements it is useful to pass `onTimeout: { screen.debug(); }` callback using `waitForOptions` parameter. +::: + +:::info +In order to properly use `findBy` and `findAllBy` queries you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0). ::: ## Queries @@ -82,7 +86,7 @@ _Note: most methods like this one return a [`ReactTestInstance`](https://reactjs type ReactTestInstance = { type: string | Function; props: { [propName: string]: any }; - parent: null | ReactTestInstance; + parent: ReactTestInstance | null; children: Array; }; ``` From 0bd37f27737100aa89f4b13270adefe199c80f83 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Fri, 30 Dec 2022 20:45:48 +0100 Subject: [PATCH 2/3] fix: timeout for findBy --- website/docs/Queries.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/Queries.md b/website/docs/Queries.md index 1f31e6f49..88f241404 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -44,7 +44,7 @@ title: Queries ### getBy -`getBy*` queries return the first matching node for a query, and throw an error if no elements match or if more than one match is found (use `getAllBy` instead). +`getBy*` queries return the first matching node for a query, and throw an error if no elements match or if more than one match is found. If you need to find more than one element, then use `getAllBy`. ### getAllBy @@ -56,11 +56,11 @@ title: Queries ### queryAllBy -`queryAllBy*` queries return an array of all matching nodes for a query, and return an empty array (`[]`) if no elements match. +`queryAllBy*` queries return an array of all matching nodes for a query, and return an empty array (`[]`) when no elements match. ### findBy -`findBy` queries return a promise which resolves when a matching element is found. The promise is rejected if no elements match or if more than one match is found after a default timeout of 4500ms. If you need to find more than one element, then use `findAllBy`. +`findBy` queries return a promise which resolves when a matching element is found. The promise is rejected if no elements match or if more than one match is found after a default timeout of 1000 ms. If you need to find more than one element, then use `findAllBy`. ### findAllBy From b7c7b82a5ed745cd33b03b1ab601d98756898554 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Mon, 2 Jan 2023 11:05:38 +0100 Subject: [PATCH 3/3] Update website/docs/Queries.md Co-authored-by: MattAgn <32499425+MattAgn@users.noreply.github.com> --- website/docs/Queries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/Queries.md b/website/docs/Queries.md index 88f241404..376434a23 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -71,7 +71,7 @@ title: Queries ::: :::info -In cases when your `findBy` and `findAllBy` queries throw when not able to find matching elements it is useful to pass `onTimeout: { screen.debug(); }` callback using `waitForOptions` parameter. +In cases when your `findBy` and `findAllBy` queries throw when not able to find matching elements it is useful to pass `onTimeout: () => { screen.debug(); }` callback using `waitForOptions` parameter. ::: :::info