From 29a7f020055a9f5317686a8bd3a1764b1e225677 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Thu, 14 May 2020 08:49:18 +0200 Subject: [PATCH 1/3] Added usage notes for ByTestId queries --- website/docs/Queries.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/docs/Queries.md b/website/docs/Queries.md index e4330e4ae..c62c2c142 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -91,6 +91,10 @@ const { getByTestId } = render(); const element = getByTestId('unique-id'); ``` +*Note:* Please be mindful when using these API and **treat it as an escape hatch**. Your users can't interact with `testID` anyhow, so you may end up writing tests that provide false sense of security. Favor text and accessibility queries instead. + +*Warning:* Current implementation of `getByTestId` and `queryByTestId` has a serious flaw, which results in finding more IDs than there really would be present in native React host components. Fixing it may break some of your tests so we'll do it in next major release (v2). As a temporary workaround, please use `getAllByTestId('your-id')[0]` or `queryAllByTestId('your-id')[0]` or migrate off testing with testID, which is considered to be an escape hatch. + ### `ByA11yLabel`, `ByAccessibilityLabel` > getByA11yLabel, getAllByA11yLabel, queryByA11yLabel, queryAllByA11yLabel From f6f9b1298a3f909f7ec61c9a1098693906bd787f Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Thu, 14 May 2020 10:04:27 +0200 Subject: [PATCH 2/3] Update website/docs/Queries.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Pierzchała --- website/docs/Queries.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/docs/Queries.md b/website/docs/Queries.md index c62c2c142..10378f2b7 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -93,7 +93,9 @@ const element = getByTestId('unique-id'); *Note:* Please be mindful when using these API and **treat it as an escape hatch**. Your users can't interact with `testID` anyhow, so you may end up writing tests that provide false sense of security. Favor text and accessibility queries instead. -*Warning:* Current implementation of `getByTestId` and `queryByTestId` has a serious flaw, which results in finding more IDs than there really would be present in native React host components. Fixing it may break some of your tests so we'll do it in next major release (v2). As a temporary workaround, please use `getAllByTestId('your-id')[0]` or `queryAllByTestId('your-id')[0]` or migrate off testing with testID, which is considered to be an escape hatch. +:::danger +Current implementation of `getByTestId` and `queryByTestId` has a serious flaw, which results in finding more IDs than there really would be present in native React host components. Fixing it may break some of your tests so we'll do it in next major release (v2). As a temporary workaround, please use `getAllByTestId('your-id')[0]` or `queryAllByTestId('your-id')[0]` or migrate off testing with testID, which is considered to be an escape hatch. +::: ### `ByA11yLabel`, `ByAccessibilityLabel` From c1d65feab4818f6807ff1a5ec973902bbacfeaca Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Thu, 14 May 2020 10:04:36 +0200 Subject: [PATCH 3/3] Update website/docs/Queries.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Pierzchała --- website/docs/Queries.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/docs/Queries.md b/website/docs/Queries.md index 10378f2b7..461e975b1 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -91,7 +91,9 @@ const { getByTestId } = render(); const element = getByTestId('unique-id'); ``` -*Note:* Please be mindful when using these API and **treat it as an escape hatch**. Your users can't interact with `testID` anyhow, so you may end up writing tests that provide false sense of security. Favor text and accessibility queries instead. +:::caution +Please be mindful when using these API and **treat it as an escape hatch**. Your users can't interact with `testID` anyhow, so you may end up writing tests that provide false sense of security. Favor text and accessibility queries instead. +::: :::danger Current implementation of `getByTestId` and `queryByTestId` has a serious flaw, which results in finding more IDs than there really would be present in native React host components. Fixing it may break some of your tests so we'll do it in next major release (v2). As a temporary workaround, please use `getAllByTestId('your-id')[0]` or `queryAllByTestId('your-id')[0]` or migrate off testing with testID, which is considered to be an escape hatch.