From 4584623c5dcf8837277987e9a37ad2b034dfd70f Mon Sep 17 00:00:00 2001 From: Ryan Castner Date: Mon, 19 Mar 2018 15:50:50 -0400 Subject: [PATCH 1/5] Add faq entry about dealing with multiple data-testid with the same value --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index c0196d00..c7e60e7e 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,20 @@ const allLisInDiv = container.querySelectorAll('div li') const rootElement = container.firstChild ``` +**What if I’m iterating over a list of items that I want to put the data-testid="item" attribute on. How do I distinguish them from each other?** + +You can make your selector just choose the one you want by including :nth-child(4) in the selector. + +```javascript +const thirdLiInUl = container.querySelector('ul > li:nth-child(3)') +``` + +Or you could include the index or an ID in your attribute: + +```javascript +
  • {item.text}
  • +``` + **What about enzyme is "bloated with complexity and features" and "encourage poor testing practices"** From 554b9a27a74a57a51d4e80ed73760e53b85fee4a Mon Sep 17 00:00:00 2001 From: Ryan Castner Date: Mon, 19 Mar 2018 15:55:21 -0400 Subject: [PATCH 2/5] Add contributor --- .all-contributorsrc | 12 +++++++++++- README.md | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5d154811..656c29c0 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -18,6 +18,16 @@ "infra", "test" ] + }, + { + "login": "audiolion", + "name": "Ryan Castner", + "avatar_url": "https://avatars1.githubusercontent.com/u/2430381?v=4", + "profile": "http://audiolion.github.io", + "contributions": [ + "doc" + ] } - ] + ], + "repoType": "github" } diff --git a/README.md b/README.md index c7e60e7e..9e8144c7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ [![downloads][downloads-badge]][npmtrends] [![MIT License][license-badge]][license] -[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc] @@ -329,8 +329,8 @@ Thanks goes to these people ([emoji key][emojis]): -| [
    Kent C. Dodds](https://kentcdodds.com)
    [šŸ’»](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Code") [šŸ“–](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Documentation") [šŸš‡](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [āš ļø](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Tests") | -| :---: | +| [
    Kent C. Dodds](https://kentcdodds.com)
    [šŸ’»](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Code") [šŸ“–](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Documentation") [šŸš‡](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [āš ļø](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Tests") | [
    Ryan Castner](http://audiolion.github.io)
    [šŸ“–](https://github.com/kentcdodds/react-testing-library/commits?author=audiolion "Documentation") | +| :---: | :---: | From dc92940158aaa78b2719c82e1801139815cbeff4 Mon Sep 17 00:00:00 2001 From: Ryan Castner Date: Mon, 19 Mar 2018 15:57:38 -0400 Subject: [PATCH 3/5] Generalize selector --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e8144c7..109f436b 100644 --- a/README.md +++ b/README.md @@ -255,7 +255,7 @@ const rootElement = container.firstChild **What if I’m iterating over a list of items that I want to put the data-testid="item" attribute on. How do I distinguish them from each other?** -You can make your selector just choose the one you want by including :nth-child(4) in the selector. +You can make your selector just choose the one you want by including :nth-child in the selector. ```javascript const thirdLiInUl = container.querySelector('ul > li:nth-child(3)') From 3eeb960f96c82201f6b2ef599bda6343273e4072 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Mon, 19 Mar 2018 14:03:07 -0600 Subject: [PATCH 4/5] Update .all-contributorsrc --- .all-contributorsrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 656c29c0..ac1c1f6b 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1,6 +1,7 @@ { "projectName": "react-testing-library", "projectOwner": "kentcdodds", + "repoType": "github", "files": [ "README.md" ], @@ -28,6 +29,5 @@ "doc" ] } - ], - "repoType": "github" + ] } From 20e4cbc0892125fcdd1769b94df0a97346bd14a5 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Mon, 19 Mar 2018 14:05:07 -0600 Subject: [PATCH 5/5] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 109f436b..26d9980e 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,14 @@ Or you could include the index or an ID in your attribute:
  • {item.text}
  • ``` +And then you could use the `queryByTestId`: + +```javascript +const items = [/* your items */] +const {queryByTestId} = render(/* your component with the items */) +const thirdItem = queryByTestId(`item-${items[2].id}`) +``` + **What about enzyme is "bloated with complexity and features" and "encourage poor testing practices"**