diff --git a/.all-contributorsrc b/.all-contributorsrc index 5d154811..ac1c1f6b 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1,6 +1,7 @@ { "projectName": "react-testing-library", "projectOwner": "kentcdodds", + "repoType": "github", "files": [ "README.md" ], @@ -18,6 +19,15 @@ "infra", "test" ] + }, + { + "login": "audiolion", + "name": "Ryan Castner", + "avatar_url": "https://avatars1.githubusercontent.com/u/2430381?v=4", + "profile": "http://audiolion.github.io", + "contributions": [ + "doc" + ] } ] } diff --git a/README.md b/README.md index c0196d00..26d9980e 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] @@ -253,6 +253,28 @@ 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 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}
  • +``` + +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"** @@ -315,8 +337,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") | +| :---: | :---: |