From ba1d1b1cc5c32214f1db3e7fd1361edfb9914e96 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Tue, 19 Mar 2019 14:50:11 -0600 Subject: [PATCH 1/2] docs: add `findBy` query type docs. Reference https://github.com/kentcdodds/dom-testing-library/pull/224 --- docs/api-queries.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/api-queries.md b/docs/api-queries.md index 321d22cf4..96d99afe3 100644 --- a/docs/api-queries.md +++ b/docs/api-queries.md @@ -26,9 +26,26 @@ present. ### queryAllBy -`queryAllBy*`queries return an array of all matching nodes for a query, and +`queryAllBy*` queries return an array of all matching nodes for a query, and return an empty array (`[]`) if no elements match. +### findBy + +`findBy*` queries return a promise which resolves when an element is found which +matches the given query. The promise is rejected if no element is found after +a default timeout of `4500`ms. + +> Note, this is a simple combination of `getBy*` queries and +> [`waitForElement`](/docs/api-async#waitforelement). The `findBy*` queries +> accept the `waitForElement` options as the last argument. (i.e. +> `findByText(container, 'text', queryOptions, waitForElementOptions)`) + +### findAllBy + +`findAllBy*` queries return a promise which resolves to an array of elements when +any elements are found which match the given query. The promise is rejected if no +elements are found after a default timeout of `4500`ms. + ## Options The argument to a query can be a _string_, _regular expression_, or _function_. From 4ccf988f93429eed01393bcc6e4117f4cf38ec35 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Tue, 19 Mar 2019 15:34:40 -0600 Subject: [PATCH 2/2] Update api-queries.md --- docs/api-queries.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/api-queries.md b/docs/api-queries.md index 96d99afe3..4d5276fd8 100644 --- a/docs/api-queries.md +++ b/docs/api-queries.md @@ -58,6 +58,7 @@ See [TextMatch](#textmatch) for documentation on what can be passed to a query. ### `ByLabelText` > getByLabelText, queryByLabelText, getAllByLabelText, queryAllByLabelText +> findByLabelText, findAllByLabelText ```typescript getByLabelText( @@ -145,7 +146,7 @@ const inputNode = getByLabelText(container, 'username', { ### `ByPlaceholderText` > getByPlaceholderText, queryByPlaceholderText, getAllByPlaceholderText, -> queryAllByPlaceholderText +> queryAllByPlaceholderText, findByPlaceholderText, findAllByPlaceholderText ```typescript getByPlaceholderText( @@ -199,7 +200,7 @@ cy.getByPlaceholderText('Username').should('exist') ### `ByText` -> getByText, queryByText, getAllByText, queryAllByText +> getByText, queryByText, getAllByText, queryAllByText, findByText, findAllByText ```typescript getByText( @@ -270,7 +271,8 @@ If you'd rather disable this behavior, set `ignore` to `false`. ### `ByAltText` -> getByAltText, queryByAltText, getAllByAltText, queryAllByAltText +> getByAltText, queryByAltText, getAllByAltText, queryAllByAltText, findByAltText, +> findAllByAltText ```typescript getByAltText( @@ -325,7 +327,8 @@ cy.getByAltText(/incredibles.*png$/i).should('exist') ### `ByTitle` -> getByTitle, queryByTitle, getAllByTitle, queryAllByTitle +> getByTitle, queryByTitle, getAllByTitle, queryAllByTitle, findByTitle, +> findAllByTitle ```typescript getByTitle( @@ -383,7 +386,7 @@ cy.getByTitle('Close').should('exist') ### `ByDisplayValue` > getByDisplayValue, queryByDisplayValue, getAllByDisplayValue, -> queryAllByDisplayValue +> queryAllByDisplayValue, findByDisplayValue, findAllByDisplayValue ```typescript getByDisplayValue( @@ -518,7 +521,8 @@ cy.getByDisplayName('Alaska').should('exist') ### `ByRole` -> getByRole, queryByRole, getAllByRole, queryAllByRole +> getByRole, queryByRole, getAllByRole, queryAllByRole, findByRole, +> findAllByRole ```typescript getByRole( @@ -567,7 +571,8 @@ cy.getByRole('dialog').should('exist') ### `ByTestId` -> getByTestId, queryByTestId, getAllByTestId, queryAllByTestId +> getByTestId, queryByTestId, getAllByTestId, queryAllByTestId, findByTestId, +> findAllByTestId ```typescript getByTestId(