Date: Sat, 18 Jan 2020 10:15:26 -0500
Subject: [PATCH 030/903] Fix copy typo to buy course
buy -> by
---
website/pages/en/support.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/website/pages/en/support.js b/website/pages/en/support.js
index e4cbf15a8..e19726dcb 100644
--- a/website/pages/en/support.js
+++ b/website/pages/en/support.js
@@ -76,7 +76,7 @@ function Support(props) {
TestingJavaScript.com course.
- You can support Kent buy purchasing a license to{' '}
+ You can support Kent by purchasing a license to{' '}
TestingJavaScript.com
From 441597c2bab76b7214ecb17a4fa5db2e3df877b1 Mon Sep 17 00:00:00 2001
From: Greg Herbowicz
Date: Fri, 24 Jan 2020 10:05:35 +0100
Subject: [PATCH 031/903] docs(useReducer): Too many rerenders fix (#365)
---
docs/example-react-hooks-useReducer.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/example-react-hooks-useReducer.md b/docs/example-react-hooks-useReducer.md
index bc85ba7f6..c817cb79f 100644
--- a/docs/example-react-hooks-useReducer.md
+++ b/docs/example-react-hooks-useReducer.md
@@ -42,7 +42,7 @@ const Example = () => {
Waiting for confirmation...
)}
- Confirm
+ dispatch({ type: 'SUCCESS' })}>Confirm
)
}
From f4f4cbd110e0d3c4bbe9fe5d45a2d5517cbf62ab Mon Sep 17 00:00:00 2001
From: Dylan Irlbeck
Date: Mon, 27 Jan 2020 17:50:48 -0600
Subject: [PATCH 032/903] Update Cypress intro.md (#364)
Currently, the hyperlink attached to `See the DOM Testing Library docs for reference` takes you to `testing-library`'s home page (`testing-library.com`). It makes more sense (for the given text) to link to the DOM Testing Library API docs, in my opinion.
---
docs/cypress-testing-library/intro.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/cypress-testing-library/intro.md b/docs/cypress-testing-library/intro.md
index debe9e8ae..abbc9a4e6 100644
--- a/docs/cypress-testing-library/intro.md
+++ b/docs/cypress-testing-library/intro.md
@@ -24,7 +24,7 @@ import '@testing-library/cypress/add-commands';
You can now use all of `DOM Testing Library`'s `findBy`, `findAllBy`, `queryBy`
and `queryAllBy` commands off the global `cy` object.
-[See the `DOM Testing Library` docs for reference](https://testing-library.com).
+[See the `DOM Testing Library` docs for reference](https://testing-library.com/docs/dom-testing-library/api-queries).
> Note: the `get*` queries are not supported because for reasonable Cypress tests you
> need retryability and `find*` queries already support that. The reason the `query*`
From 1070edf77cc2e88106e17d5302555e8ce07ebefc Mon Sep 17 00:00:00 2001
From: Nataliia Pylypenko <33361478+pylnata@users.noreply.github.com>
Date: Tue, 28 Jan 2020 20:39:14 +0100
Subject: [PATCH 033/903] Update example-react-router.md (#366)
* Update example-react-router.md
React must be in scope when using JSX
* Update example-react-router.md
exports and imports fixed
---
docs/example-react-router.md | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/docs/example-react-router.md b/docs/example-react-router.md
index 49e792278..eedee0acf 100644
--- a/docs/example-react-router.md
+++ b/docs/example-react-router.md
@@ -7,7 +7,7 @@ title: React Router
// app.js
import React from 'react'
import { withRouter } from 'react-router'
-import { Link, Route, Router, Switch } from 'react-router-dom'
+import { Link, Route, Switch } from 'react-router-dom'
const About = () => You are on the about page
const Home = () => You are home
@@ -31,14 +31,18 @@ function App() {
)
}
+
+export { LocationDisplay, App }
```
```jsx
// app.test.js
+import React from 'react'
import { Router } from 'react-router-dom'
import { createMemoryHistory } from 'history'
import { render, fireEvent } from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'
+import { LocationDisplay, App } from './app'
test('full app rendering/navigating', () => {
const history = createMemoryHistory()
From bf88ea1d9d37e003cae82a84304ffc77bc7e7556 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 28 Jan 2020 12:39:43 -0700
Subject: [PATCH 034/903] docs: add pylnata as a contributor (#370)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 978480196..9f4c63975 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -485,6 +485,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "pylnata",
+ "name": "Nataliia Pylypenko",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/33361478?v=4",
+ "profile": "https://github.com/pylnata",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 265f604a8..508543840 100644
--- a/README.md
+++ b/README.md
@@ -102,6 +102,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Dustin Masters π
Darren Lester π
Iswara Chaitanya π
+ Nataliia Pylypenko π
From 60da1be7de20f80115646ab82ffeb825f7c56361 Mon Sep 17 00:00:00 2001
From: Hu Chen
Date: Wed, 29 Jan 2020 06:27:44 +0800
Subject: [PATCH 035/903] Update setup.md (#369)
because @babel/polyfill is deprecated in 7.4.0 https://babeljs.io/docs/en/next/babel-polyfill
---
docs/dom-testing-library/setup.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/dom-testing-library/setup.md b/docs/dom-testing-library/setup.md
index fa4263359..dcf56fc16 100644
--- a/docs/dom-testing-library/setup.md
+++ b/docs/dom-testing-library/setup.md
@@ -34,5 +34,5 @@ mocha --require jsdom-global/register
```
> Note, depending on the version of Node you're running, you may also need to
-> install `@babel/polyfill` (if you're using babel 7) or `babel-polyfill` (for
-> babel 6).
+> add `core-js` and `regenerator-runtime` (if you're using babel 7) or
+> `babel-polyfill` (for babel 6).
From 0cccb303328454449137361c895c44bdfd840547 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 28 Jan 2020 15:28:11 -0700
Subject: [PATCH 036/903] docs: add huchenme as a contributor (#371)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 9f4c63975..5e60a5eef 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -494,6 +494,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "huchenme",
+ "name": "Hu Chen",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/2078389?v=4",
+ "profile": "https://huchen.dev/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 508543840..e11732378 100644
--- a/README.md
+++ b/README.md
@@ -103,6 +103,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Darren Lester π
Iswara Chaitanya π
Nataliia Pylypenko π
+ Hu Chen π
From 81ce42df83af1bcdee47c2dbe0003051f9f98dd7 Mon Sep 17 00:00:00 2001
From: Josh
Date: Tue, 28 Jan 2020 15:42:14 -0700
Subject: [PATCH 037/903] Add documentation for screen.debug. (#362)
* Add documentation for screen.debug.
* Update api-queries.md
* Update api-queries.md
* Update api-queries.md
Co-authored-by: Kent C. Dodds
---
docs/dom-testing-library/api-queries.md | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index 7b9ff55b5..9787eb037 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -81,6 +81,29 @@ document.body.innerHTML = exampleHTML
const exampleInput = screen.getByLabelText(/example/i)
```
+### `screen.debug`
+
+For convenience screen also exposes a `debug` method in addition to the queries.
+This method is essentially a shortcut for `console.log(prettyDOM())`. It
+supports debugging the document, a single element, or an array of elements.
+
+```javascript
+import {screen} from '@testing-library/dom'
+
+document.body.innerHTML = `
+ test
+ multi-test
+ multi-test
+`
+
+// debug document
+screen.debug()
+// debug single element
+screen.debug(screen.getByText('test'))
+// debug multiple elements
+screen.debug(screen.getAllByText('multi-test'))
+```
+
## Queries
> NOTE: These queries are the base queries and require you pass a `container` as
From 246c0cfc8438a5008184fe69c4ca03f7b3ee63ac Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 28 Jan 2020 15:42:45 -0700
Subject: [PATCH 038/903] docs: add jkdowdle as a contributor (#372)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 5e60a5eef..af08984f5 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -503,6 +503,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "jkdowdle",
+ "name": "Josh",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/19804196?v=4",
+ "profile": "https://github.com/jkdowdle",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index e11732378..cf031a05c 100644
--- a/README.md
+++ b/README.md
@@ -104,6 +104,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Iswara Chaitanya π
Nataliia Pylypenko π
Hu Chen π
+ Josh π
From 324790e80632902c8026d47e6ed3daf57a48afff Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Wed, 19 Feb 2020 17:15:01 -0700
Subject: [PATCH 039/903] add link to Netlify per their new terms of service
---
website/core/Footer.js | 3 +++
1 file changed, 3 insertions(+)
diff --git a/website/core/Footer.js b/website/core/Footer.js
index eaeb2b71d..774c3e766 100755
--- a/website/core/Footer.js
+++ b/website/core/Footer.js
@@ -81,6 +81,9 @@ class Footer extends React.Component {
Edit Docs on GitHub
+
+ Hosted by Netlify
+
{this.props.config.copyright}
From 4547b98e4a26ff35721b903b196b186696990812 Mon Sep 17 00:00:00 2001
From: Maxence Poutord
Date: Tue, 25 Feb 2020 12:31:11 +0000
Subject: [PATCH 040/903] docs: add missing examples for vue-testing-library
See: https://github.com/testing-library/vue-testing-library\#more-examples
---
docs/vue-testing-library/examples.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs/vue-testing-library/examples.md b/docs/vue-testing-library/examples.md
index db1a39120..0a1498d2d 100644
--- a/docs/vue-testing-library/examples.md
+++ b/docs/vue-testing-library/examples.md
@@ -102,3 +102,5 @@ Some included are:
- [`vuex`](https://github.com/testing-library/vue-testing-library/blob/master/src/__tests__/vuex.js)
- [`vue-router`](https://github.com/testing-library/vue-testing-library/tree/master/src/__tests__/vue-router.js)
- [`vee-validate`](https://github.com/testing-library/vue-testing-library/tree/master/src/__tests__/validate-plugin.js)
+- [`vue-i18n`](https://github.com/testing-library/vue-testing-library/blob/master/src/__tests__/vueI18n.js)
+- [`vuetify`](https://github.com/testing-library/vue-testing-library/blob/master/src/__tests__/vuetify.js)
From 4bbe0f9b66f65a5f94154ac91f79a48e7b831078 Mon Sep 17 00:00:00 2001
From: numb86 <16703337+numb86@users.noreply.github.com>
Date: Wed, 26 Feb 2020 18:11:50 +0900
Subject: [PATCH 041/903] docs: fix fragment identifier (#379)
---
docs/react-testing-library/setup.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/react-testing-library/setup.md b/docs/react-testing-library/setup.md
index 80d75b6da..6a18df37d 100644
--- a/docs/react-testing-library/setup.md
+++ b/docs/react-testing-library/setup.md
@@ -102,7 +102,7 @@ module.exports = {
You can define your own custom queries as described in the example in the
[Helpers API](/docs/dom-testing-library/api-helpers) documentation, or via the
-[`buildQueries`](/docs/dom-testing-library/api-helpers#buildQueries) helper. Then
+[`buildQueries`](/docs/dom-testing-library/api-helpers#buildqueries) helper. Then
you can use them in any render call using the `queries` option. To make the
custom queries available globally, you can add them to your custom render method
as shown below.
From af00c4fd02b4f0e17c47afbe7cf1d2fc99e49a66 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Wed, 26 Feb 2020 10:39:35 +0100
Subject: [PATCH 042/903] docs: add numb86 as a contributor (#380)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
---
.all-contributorsrc | 9 +++++++++
README.md | 3 +++
2 files changed, 12 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index af08984f5..dd09e9564 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -512,6 +512,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "numb86",
+ "name": "numb86",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/16703337?v=4",
+ "profile": "https://numb86.net/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index cf031a05c..de0cd8974 100644
--- a/README.md
+++ b/README.md
@@ -106,6 +106,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Hu Chen π
Josh π
+
+ numb86 π
+
From 94b92eaaf2042ecb07e5477fc6352ee2005fb13d Mon Sep 17 00:00:00 2001
From: numb86 <16703337+numb86@users.noreply.github.com>
Date: Fri, 28 Feb 2020 15:37:02 +0900
Subject: [PATCH 043/903] docs: fix broken link (#383)
---
docs/react-testing-library/api.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/react-testing-library/api.md b/docs/react-testing-library/api.md
index b3508770e..7c9eb45aa 100644
--- a/docs/react-testing-library/api.md
+++ b/docs/react-testing-library/api.md
@@ -176,7 +176,7 @@ debug()
```
This is a simple wrapper around `prettyDOM` which is also exposed and comes from
-[`DOM Testing Library`](https://github.com/testing-library/dom-testing-library/blob/master/README.md#prettydom).
+[`DOM Testing Library`](dom-testing-library/api-helpers.md#prettydom).
### `rerender`
From cf1eebedf030fc7f0b0f805c330d92532e4fda1d Mon Sep 17 00:00:00 2001
From: Jordan Cutler
Date: Tue, 3 Mar 2020 10:34:01 -0800
Subject: [PATCH 044/903] docs: add Gusto to Testing Library Users (#388)
---
website/siteConfig.js | 6 ++++++
website/static/img/users/gusto.svg | 1 +
2 files changed, 7 insertions(+)
create mode 100644 website/static/img/users/gusto.svg
diff --git a/website/siteConfig.js b/website/siteConfig.js
index 99b0254a7..0d5bc0a06 100755
--- a/website/siteConfig.js
+++ b/website/siteConfig.js
@@ -106,6 +106,12 @@ const users = [
infoLink: 'https://radity.com/',
pinned: true,
},
+ {
+ caption: 'Gusto',
+ image: '/img/users/gusto.svg',
+ infoLink: 'https://gusto.com/',
+ pinned: true,
+ },
]
const siteConfig = {
diff --git a/website/static/img/users/gusto.svg b/website/static/img/users/gusto.svg
new file mode 100644
index 000000000..320bfc327
--- /dev/null
+++ b/website/static/img/users/gusto.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
From 34483192fa5bd76d5419eb2803e016120c6e5048 Mon Sep 17 00:00:00 2001
From: Nicholas Boll
Date: Tue, 3 Mar 2020 11:34:46 -0700
Subject: [PATCH 045/903] docs: Update Cypress Testing Library scoping example
(#373)
* docs: Update Cypress Testing Library scoping example
Recently https://github.com/testing-library/cypress-testing-library/pull/108 added a way to take the previous subject of a previous command to scope the query. Also `find*` queries handle `.should('not.exist')` and should be preferred over `query*` which require additional logic for eventual non-existence queries.
* docs: update note about other query types
---
docs/cypress-testing-library/intro.md | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/docs/cypress-testing-library/intro.md b/docs/cypress-testing-library/intro.md
index abbc9a4e6..2bc1d1228 100644
--- a/docs/cypress-testing-library/intro.md
+++ b/docs/cypress-testing-library/intro.md
@@ -27,9 +27,9 @@ and `queryAllBy` commands off the global `cy` object.
[See the `DOM Testing Library` docs for reference](https://testing-library.com/docs/dom-testing-library/api-queries).
> Note: the `get*` queries are not supported because for reasonable Cypress tests you
-> need retryability and `find*` queries already support that. The reason the `query*`
-> variants are supported is to allow you to assert that elements do _not_ appear on
-> the screen.
+> need retryability and `find*` queries already support that. `query*` queries are no longer
+> necessary since v5 and will be removed in v6. `find*` fully support built-in Cypress
+> assertions (removes the only use-case for `query*`).
## With TypeScript
@@ -53,12 +53,12 @@ To show some simple examples (from
```javascript
cy.findAllByText('Jackie Chan').click()
-cy.queryByText('Button Text').should('exist')
-cy.queryByText('Non-existing Button Text').should('not.exist')
-cy.queryByLabelText('Label text', {timeout: 7000}).should('exist')
-cy.get('form').within(() => {
- cy.findByText('Button Text').should('exist')
-})
+cy.findByText('Button Text').should('exist')
+cy.findByText('Non-existing Button Text').should('not.exist')
+cy.findByLabelText('Label text', {timeout: 7000}).should('exist')
+
+// findAllByText _inside_ a form element
+cy.get('form').findByText('Button Text').should('exist')
cy.get('form').then(subject => {
cy.findByText('Button Text', {container: subject}).should('exist')
})
From 3250aa771e7cf947a5a89421ba0c15657abd5716 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 3 Mar 2020 11:36:12 -0700
Subject: [PATCH 046/903] docs: add NicholasBoll as a contributor (#390)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index dd09e9564..353147073 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -521,6 +521,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "NicholasBoll",
+ "name": "Nicholas Boll",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/338257?v=4",
+ "profile": "https://github.com/NicholasBoll",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index de0cd8974..265f95b68 100644
--- a/README.md
+++ b/README.md
@@ -108,6 +108,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
numb86 π
+ Nicholas Boll π
From 43a0600ae74df9a40bf8be5a87f8d1f3ded09fb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pete=20Nyk=C3=A4nen?=
Date: Tue, 3 Mar 2020 20:41:17 +0200
Subject: [PATCH 047/903] Update Cypress documentation reference from
getByLabelText to findByLabelText (#377)
---
docs/dom-testing-library/api-queries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index 9787eb037..26f49316f 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -182,7 +182,7 @@ const inputNode = getByLabelText('username')
```js
-cy.getByLabelText('username').should('exist')
+cy.findByLabelText('username').should('exist')
```
From b96f4620dcb6a9c44dbfc9a197ad9b21e7f09f81 Mon Sep 17 00:00:00 2001
From: Billy Mathews
Date: Tue, 3 Mar 2020 19:08:58 +0000
Subject: [PATCH 048/903] Add my react-testing-library talk to learning.md
(#375)
---
docs/learning.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/docs/learning.md b/docs/learning.md
index 85bdf5168..d9622189a 100644
--- a/docs/learning.md
+++ b/docs/learning.md
@@ -36,5 +36,6 @@ sidebar_label: Learning Material
by [Scott Sauber](https://github.com/scottsauber)
- [How to Test Asynchronous Methods](https://www.polvara.me/posts/how-to-test-asynchronous-methods/)
by [Gpx](https://twitter.com/Gpx)
+- [Writing better tests with react-testing-library](https://www.youtube.com/watch?v=O0VxvRqgm7g) by [Billy Mathews](https://twitter.com/BillRMathews)
Feel free to contribute more!
From 581cd66010407e605b1d6344a4da32b2a8943064 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 3 Mar 2020 12:09:41 -0700
Subject: [PATCH 049/903] docs: add Billy as a contributor (#391)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
---
.all-contributorsrc | 10 ++++++++++
README.md | 1 +
2 files changed, 11 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 353147073..199d8cf61 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -530,6 +530,16 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "Billy",
+ "name": "Billy",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/48111?v=4",
+ "profile": "https://github.com/billy",
+ "contributions": [
+ "talk",
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 265f95b68..dbe9664b6 100644
--- a/README.md
+++ b/README.md
@@ -109,6 +109,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
numb86 π
Nicholas Boll π
+ Billy π’ π
From eba42571e6fcf13bfc39581d77f98b05fbb1f3d0 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Wed, 4 Mar 2020 08:41:38 -0700
Subject: [PATCH 050/903] Fix billy in README.md
Whoops https://github.com/testing-library/testing-library-docs/pull/391#issuecomment-594565228
cc @Billy-
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index dbe9664b6..f0ead144c 100644
--- a/README.md
+++ b/README.md
@@ -109,7 +109,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
numb86 π
Nicholas Boll π
- Billy π’ π
+ Billy Mathews π’ π
From 1b8c4efbfd713e0717d1ac4744144bd3722d6e65 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Wed, 4 Mar 2020 08:42:29 -0700
Subject: [PATCH 051/903] Fix billy in .all-contributorsrc
Whoops https://github.com/testing-library/testing-library-docs/pull/391#issuecomment-594565228
cc @Billy-
---
.all-contributorsrc | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 199d8cf61..28a268cdd 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -532,10 +532,10 @@
]
},
{
- "login": "Billy",
- "name": "Billy",
- "avatar_url": "https://avatars2.githubusercontent.com/u/48111?v=4",
- "profile": "https://github.com/billy",
+ "login": "Billy-",
+ "name": "Billy Matthews",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/4316168?v=4",
+ "profile": "https://github.com/Billy-",
"contributions": [
"talk",
"doc"
From f6b73763b99dd743eac1a4492a14cf9db6463ccd Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Wed, 4 Mar 2020 12:09:57 -0700
Subject: [PATCH 052/903] add note about debug params
---
docs/react-testing-library/api.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/docs/react-testing-library/api.md b/docs/react-testing-library/api.md
index 7c9eb45aa..f55b327bb 100644
--- a/docs/react-testing-library/api.md
+++ b/docs/react-testing-library/api.md
@@ -173,6 +173,10 @@ debug()
// Hello World
//
// you can also pass an element: debug(getByTestId('messages'))
+// and you can pass all the same arguemnts to debug as you can
+// to prettyDOM:
+// const maxLengthToPrint = 10000
+// debug(getByTestId('messages'), maxLengthToPrint, {highlight: false})
```
This is a simple wrapper around `prettyDOM` which is also exposed and comes from
From 50cba937a2c228a60d457c805429fe4c511250ca Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Wed, 4 Mar 2020 12:14:11 -0700
Subject: [PATCH 053/903] Fix arguments typo (#392)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Caught the typo in @kentcdodds live stream π
---
docs/react-testing-library/api.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/react-testing-library/api.md b/docs/react-testing-library/api.md
index f55b327bb..936e67e60 100644
--- a/docs/react-testing-library/api.md
+++ b/docs/react-testing-library/api.md
@@ -173,7 +173,7 @@ debug()
// Hello World
//
// you can also pass an element: debug(getByTestId('messages'))
-// and you can pass all the same arguemnts to debug as you can
+// and you can pass all the same arguments to debug as you can
// to prettyDOM:
// const maxLengthToPrint = 10000
// debug(getByTestId('messages'), maxLengthToPrint, {highlight: false})
From c4c0ac2f1bbbbb93401cd59fba906972d6788bcb Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Wed, 4 Mar 2020 12:15:32 -0700
Subject: [PATCH 054/903] docs: add dale-french as a contributor (#393)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
---
.all-contributorsrc | 9 +++++++++
README.md | 3 ++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 28a268cdd..d36c74f8f 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -540,6 +540,15 @@
"talk",
"doc"
]
+ },
+ {
+ "login": "dale-french",
+ "name": "Dale French",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/6544116?v=4",
+ "profile": "https://github.com/dale-french",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index f0ead144c..1c0411fce 100644
--- a/README.md
+++ b/README.md
@@ -109,7 +109,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
numb86 π
Nicholas Boll π
- Billy Mathews π’ π
+ Billy Matthews π’ π
+ Dale French π
From f3ce6df1fac2a25a8440c460fc87bad27c9005c6 Mon Sep 17 00:00:00 2001
From: aw-davidson <32170938+aw-davidson@users.noreply.github.com>
Date: Thu, 5 Mar 2020 21:10:35 -0500
Subject: [PATCH 055/903] Add docs for getElementError config option (#376)
Co-authored-by: davidsa
---
docs/dom-testing-library/api-configuration.md | 21 +++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/docs/dom-testing-library/api-configuration.md b/docs/dom-testing-library/api-configuration.md
index 66577ef74..9bd93e47e 100644
--- a/docs/dom-testing-library/api-configuration.md
+++ b/docs/dom-testing-library/api-configuration.md
@@ -21,6 +21,10 @@ Configuration options:
`testIdAttribute`: The attribute used by [`getByTestId`](api-queries#bytestid)
and related queries. Defaults to `data-testid`.
+`getElementError`: A function that returns the error used when
+[`getBy*`](api-queries#getby) or [`getAllBy*`](api-queries#getallby) fail. Takes
+the error message and container object as arguments.
+
@@ -28,8 +32,17 @@ and related queries. Defaults to `data-testid`.
```js
// setup-tests.js
import { configure } from '@testing-library/dom'
-
-configure({testIdAttribute: 'data-my-test-id'})
+import serialize from 'my-custom-dom-serializer'
+
+configure({
+ testIdAttribute: 'data-my-test-id',
+ getElementError: (message, container) => {
+ const customMessage = [message, serialize(container.firstChild)].join(
+ '\n\n'
+ )
+ return new Error(customMessage)
+ },
+})
```
@@ -38,7 +51,7 @@ configure({testIdAttribute: 'data-my-test-id'})
// setup-tests.js
import { configure } from '@testing-library/react'
-configure({testIdAttribute: 'data-my-test-id'})
+configure({ testIdAttribute: 'data-my-test-id' })
```
@@ -47,7 +60,7 @@ configure({testIdAttribute: 'data-my-test-id'})
// setup-tests.js
import { configure } from '@testing-library/cypress'
-configure({testIdAttribute: 'data-my-test-id'})
+configure({ testIdAttribute: 'data-my-test-id' })
```
From 444ccf791db95c7310d27396e66a4be1a8d49d9a Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Thu, 5 Mar 2020 19:11:10 -0700
Subject: [PATCH 056/903] docs: add aw-davidson as a contributor (#397)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index d36c74f8f..028e6ee85 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -549,6 +549,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "aw-davidson",
+ "name": "aw-davidson",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/32170938?v=4",
+ "profile": "https://github.com/aw-davidson",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 1c0411fce..9258d6e76 100644
--- a/README.md
+++ b/README.md
@@ -111,6 +111,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Nicholas Boll π
Billy Matthews π’ π
Dale French π
+ aw-davidson π
From e49f159b97f67a4dd5d75e42e8d066a38dcd441b Mon Sep 17 00:00:00 2001
From: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
Date: Fri, 6 Mar 2020 18:03:38 +0700
Subject: [PATCH 057/903] docs(dom-testing-library): Fix typo (#398)
---
docs/dom-testing-library/api-helpers.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-helpers.md b/docs/dom-testing-library/api-helpers.md
index 37f525849..1d3cc6cd4 100644
--- a/docs/dom-testing-library/api-helpers.md
+++ b/docs/dom-testing-library/api-helpers.md
@@ -87,7 +87,7 @@ and add it here!
getNodeText(node: HTMLElement)
```
-Returns the complete text content of a html element, removing any extra
+Returns the complete text content of an HTML element, removing any extra
whitespace. The intention is to treat text in nodes exactly as how it is
perceived by users in a browser, where any extra whitespace within words in the
html code is not meaningful when the text is rendered.
From 9dd8b32fcb993f36e2079d1da44500bc1a8eb8a1 Mon Sep 17 00:00:00 2001
From: Sebastian Silbermann
Date: Fri, 6 Mar 2020 17:42:42 +0100
Subject: [PATCH 058/903] feat(byRole): Add `name` option (#368)
* feat(byRole): Add `name` option
* Recommend byRole more
* resolve Kent's review
* Try another query recommendation
* Fix more by*
---
docs/dom-testing-library/api-queries.md | 27 +++++++++++++++++++++++--
docs/guide-which-query.md | 11 ++++++----
2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index 26f49316f..ee34ba188 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -187,8 +187,12 @@ cy.findByLabelText('username').should('exist')
-It will NOT find the input node for label text broken up by elements. For this
-case, you can provide a `selector` in the options:
+It will NOT find the input node for label text broken up by elements. You can
+use `getByRole('textbox', { name: 'Username' })` instead which is robust against
+switching to `aria-label` or `aria-labelledby`.
+
+If it is important that you query an actual `` element you can provide a
+`selector` in the options:
```html
Username
@@ -590,6 +594,7 @@ getByRole(
options?: {
exact?: boolean = true,
hidden?: boolean = true,
+ name?: TextMatch,
normalizer?: NormalizerFn,
}): HTMLElement
```
@@ -604,6 +609,24 @@ Library uses `aria-query` under the hood to find those elements by their default
ARIA roles, you can find in their docs
[which HTML Elements with inherent roles are mapped to each role](https://github.com/A11yance/aria-query#elements-to-roles).
+You can query the returned element(s) by their
+[accessible name](https://www.w3.org/TR/accname-1.1/). The accessible name is
+for simple cases equal to e.g. the label of a form element, or the text content
+of a button, or the value of the `aria-label` attribute. It can be used to query
+a specific element if multiple elements with the same role are present on the
+rendered content. For an in-depth guide check out
+["What is an accessible name?" from ThePacielloGroup](https://developer.paciellogroup.com/blog/2017/04/what-is-an-accessible-name/).
+If you only query for a single element with `getByText('The name')` it's
+oftentimes better to use `getByRole(expectedRole, { name: 'The name' })`. The
+accessible name query does not replace other queries such as `*ByAlt` or
+`*ByTitle`. While the accessible name can be equal to these attributes, it does
+not replace the functionality of these attributes. For example
+` ` will be returned for both
+`getByAlt('fancy image')` and `getByRole('image', { name: 'fancy image' })`.
+However, the image will not display its description if `fancy.jpg` could not be
+loaded. Whether you want assert this functionality in your test or not is up to
+you.
+
If you set `hidden` to `true` elements that are normally excluded from the
accessibility tree are considered for the query as well. The default behavior
follows https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion with the exception of
diff --git a/docs/guide-which-query.md b/docs/guide-which-query.md
index bcca97343..30312a604 100644
--- a/docs/guide-which-query.md
+++ b/docs/guide-which-query.md
@@ -17,9 +17,14 @@ possible. With this in mind, we recommend this order of priority:
1. `getByPlaceholderText`:
[A placeholder is not a substitute for a label](https://www.nngroup.com/articles/form-design-placeholders/).
But if that's all you have, then it's better than alternatives.
+ 1. `getByRole`: This can be used to query every element that is exposed in
+ the
+ [accessibility tree](https://developer.mozilla.org/en-US/docs/Glossary/AOM).
+ With the `name` option you can filter the returned elements by their
+ [accessible name](https://www.w3.org/TR/accname-1.1/). This should be your
+ top preference for interactive elements such as buttons.
1. `getByText`: Not useful for forms, but this is the number 1 method a user
- finds other elements (like buttons to click), so it should be your top
- preference for non-form elements.
+ finds most non-interactive elements (listitems or divs).
1. `getByDisplayValue`: The current value of a form element can be useful
when navigating a page with filled-in values.
1. **Semantic Queries** HTML5 and ARIA compliant selectors. Note that the user
@@ -29,8 +34,6 @@ possible. With this in mind, we recommend this order of priority:
`area`, and `input`), then you can use this to find that element.
1. `getByTitle`: The title attribute is not consistently read by
screenreaders, and is not visible by default for sighted users
- 1. `getByRole`: This can be used to select dialog boxes and other
- difficult-to-capture elements in a more semantic way
1. **Test IDs**
1. `getByTestId`: The user cannot see (or hear) these, so this is only
recommended for cases where you can't match by role or text or it doesn't
From 0713c86e8d512900fb247d69968cad1848adcc73 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Tue, 10 Mar 2020 09:56:15 -0600
Subject: [PATCH 059/903] fix reducer test
Closes #399
---
docs/example-react-hooks-useReducer.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/example-react-hooks-useReducer.md b/docs/example-react-hooks-useReducer.md
index c817cb79f..055e4255b 100644
--- a/docs/example-react-hooks-useReducer.md
+++ b/docs/example-react-hooks-useReducer.md
@@ -63,7 +63,7 @@ import Example from './example.js'
it('shows success message after confirm button is clicked', () => {
const { getByText } = render( )
- expect(getByText(/waiting/i).textContent).toBeInTheDocument()
+ expect(getByText(/waiting/i)).toBeInTheDocument()
fireEvent.click(getByText('Confirm'))
From 64fd6f01a0984e3c482cdaad0e826a9d6047d6a2 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Tue, 10 Mar 2020 19:26:48 -0600
Subject: [PATCH 060/903] Update example-react-hooks-useReducer.md
---
docs/example-react-hooks-useReducer.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/example-react-hooks-useReducer.md b/docs/example-react-hooks-useReducer.md
index 055e4255b..954c67efa 100644
--- a/docs/example-react-hooks-useReducer.md
+++ b/docs/example-react-hooks-useReducer.md
@@ -67,6 +67,6 @@ it('shows success message after confirm button is clicked', () => {
fireEvent.click(getByText('Confirm'))
- expect(getByText('Confirmed')).toBeInTheDocument()
+ expect(getByText('Confirmed!')).toBeInTheDocument()
})
```
From 2fb5ea1b2718898a6211faec3b269dc127731b45 Mon Sep 17 00:00:00 2001
From: Benjamin Blackwood
Date: Thu, 12 Mar 2020 22:18:31 +1100
Subject: [PATCH 061/903] docs(intro): fix typo in solution section (#400)
---
docs/react-testing-library/intro.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/react-testing-library/intro.md b/docs/react-testing-library/intro.md
index 0637887d5..055bbb337 100644
--- a/docs/react-testing-library/intro.md
+++ b/docs/react-testing-library/intro.md
@@ -36,7 +36,7 @@ primary guiding principle is:
So rather than dealing with instances of rendered React components, your tests
will work with actual DOM nodes. The utilities this library provides facilitate
-querying the DOM in the same way the user would. Finding for elements by their
+querying the DOM in the same way the user would. Finding form elements by their
label text (just like a user would), finding links and buttons from their text
(like a user would). It also exposes a recommended way to find elements by a
`data-testid` as an "escape hatch" for elements where the text content and label
From 41ab33b48fc10bf2bc35c1272ca0f2153ba35da5 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Thu, 12 Mar 2020 12:21:41 +0100
Subject: [PATCH 062/903] docs: add BBlackwo as a contributor (#401)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 028e6ee85..f00706346 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -558,6 +558,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "BBlackwo",
+ "name": "Benjamin Blackwood",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/7598058?v=4",
+ "profile": "https://twitter.com/B_Blackwo",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 9258d6e76..e61b94ab8 100644
--- a/README.md
+++ b/README.md
@@ -112,6 +112,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Billy Matthews π’ π
Dale French π
aw-davidson π
+ Benjamin Blackwood π
From 5a4813b0e2f15616befad579a22b3caaadb7b71c Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Fri, 13 Mar 2020 07:08:36 -0600
Subject: [PATCH 063/903] docs: update async utility (#394)
* update async utility documentation for next major
* Update docs/dom-testing-library/api-async.md
Co-authored-by: Sebastian Silbermann
---
docs/dom-testing-library/api-async.md | 201 +++++++++++---------------
1 file changed, 84 insertions(+), 117 deletions(-)
diff --git a/docs/dom-testing-library/api-async.md b/docs/dom-testing-library/api-async.md
index 24008c9db..017aa8e3b 100644
--- a/docs/dom-testing-library/api-async.md
+++ b/docs/dom-testing-library/api-async.md
@@ -7,116 +7,103 @@ Several utilities are provided for dealing with asynchronous code. These can be
useful to wait for an element to appear or disappear in response to an action.
(See the [guide to testing disappearance](guide-disappearance.md).)
+All the async utils are built on top of `wait`.
+
## `wait`
```typescript
-function wait(
- callback?: () => void,
+function wait(
+ callback: () => void,
options?: {
+ container?: HTMLElement
timeout?: number
interval?: number
+ mutationObserverOptions?: MutationObserverInit
}
-): Promise
+): Promise
```
-When in need to wait for non-deterministic periods of time you can use `wait`,
-to wait for your expectations to pass. The `wait` function is a small wrapper
-around the
-[`wait-for-expect`](https://github.com/TheBrainFamily/wait-for-expect) module.
-Here's a simple example:
+When in need to wait for any period of time you can use `wait`, to wait for your
+expectations to pass. Here's a simple example:
```javascript
// ...
// Wait until the callback does not throw an error. In this case, that means
// it'll wait until we can get a form control with a label that matches "username".
-await wait(() => getByLabelText(container, 'username'))
-getByLabelText(container, 'username').value = 'chucknorris'
+await wait(() => expect(mockAPI).toHaveBeenCalledTimes(1))
// ...
```
This can be useful if you have a unit test that mocks API calls and you need to
wait for your mock promises to all resolve.
-The default `callback` is a no-op function (used like `await wait()`). This can
-be helpful if you only need to wait for one tick of the event loop (in the case
-of mocked API calls with promises that resolve immediately).
-
-The default `timeout` is `4500ms` which will keep you under
-[Jest's default timeout of `5000ms`](https://facebook.github.io/jest/docs/en/jest-object.html#jestsettimeouttimeout).
+The default `container` is the global `document`. Make sure the elements you
+wait for are descendants of `container`.
The default `interval` is `50ms`. However it will run your callback immediately
-on the next tick of the event loop (in a `setTimeout`) before starting the
-intervals.
+before starting the intervals.
+
+The default `timeout` is `1000ms` which will keep you under
+[Jest's default timeout of `5000ms`](https://jestjs.io/docs/en/jest-object.html#jestsettimeouttimeout).
+
+ The default `mutationObserverOptions` is
+`{subtree: true, childList: true, attributes: true, characterData: true}` which
+will detect additions and removals of child elements (including text nodes) in
+the `container` and any of its descendants. It will also detect attribute
+changes. When any of those changes occur, it will re-run the callback.
-## `waitForElement`
+## `waitForElementToBeRemoved`
```typescript
-function waitForElement(
- callback: () => T,
+function waitForElementToBeRemoved(
+ callback: (() => T) | T,
options?: {
container?: HTMLElement
timeout?: number
+ interval?: number
mutationObserverOptions?: MutationObserverInit
}
): Promise
```
-When in need to wait for DOM elements to appear, disappear, or change you can
-use `waitForElement`. The `waitForElement` function is a small wrapper around
-the
-[`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver).
+To wait for the removal of element(s) from the DOM you can use
+`waitForElementToBeRemoved`. The `waitForElementToBeRemoved` function is a small
+wrapper around the `wait` utility.
-Here's a simple example:
+The first argument must be an element, array of elements, or a callback which returns
+an element or array of elements.
+
+Here is an example where the promise resolves with `true` because the element is
+removed:
```javascript
-// ...
-// Wait until the callback does not throw an error and returns a truthy value. In this case, that means
-// it'll wait until we can get a form control with a label that matches "username".
-// The difference from `wait` is that rather than running your callback on
-// an interval, it's run as soon as there are DOM changes in the container
-// and returns the value returned by the callback.
-const usernameElement = await waitForElement(
- () => getByLabelText(container, 'username'),
- { container }
-)
-usernameElement.value = 'chucknorris'
-// ...
-```
+const el = document.querySelector('div.getOuttaHere')
-You can also wait for multiple elements at once:
+waitForElementToBeRemoved(document.querySelector('div.getOuttaHere'))
+ .then(() => console.log('Element no longer in DOM'))
-```javascript
-const [usernameElement, passwordElement] = await waitForElement(
- () => [
- getByLabelText(container, 'username'),
- getByLabelText(container, 'password'),
- ],
- { container }
-)
+el.setAttribute('data-neat', true)
+// other mutations are ignored...
+
+el.parentElement.removeChild(el)
+// logs 'Element no longer in DOM'
```
-Using
-[`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
-is more efficient than polling the DOM at regular intervals with `wait`. This
-library sets up a
-[`'mutationobserver-shim'`](https://github.com/megawac/MutationObserver.js) on
-the global `window` object for cross-platform compatibility with older browsers
-and the [`jsdom`](https://github.com/jsdom/jsdom/issues/639) that is usually
-used in Node-based tests.
+`waitForElementToBeRemoved` will throw an error if the first argument is `null`
+or an empty array:
-The default `container` is the global `document`. Make sure the elements you
-wait for will be attached to it, or set a different `container`.
+```javascript
+waitForElementToBeRemoved(null).catch(err => console.log(err))
+waitForElementToBeRemoved(queryByText(/not here/i)).catch(err => console.log(err))
+waitForElementToBeRemoved(queryAllByText(/not here/i)).catch(err => console.log(err))
+waitForElementToBeRemoved(() => getByText(/not here/i)).catch(err => console.log(err))
-The default `timeout` is `4500ms` which will keep you under
-[Jest's default timeout of `5000ms`](https://facebook.github.io/jest/docs/en/jest-object.html#jestsettimeouttimeout).
+// Error: The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.
+```
- The default `mutationObserverOptions` is
-`{subtree: true, childList: true, attributes: true, characterData: true}` which
-will detect additions and removals of child elements (including text nodes) in
-the `container` and any of its descendants. It will also detect attribute
-changes.
+The options object is forwarded to `wait`.
-## `waitForDomChange`
+## `waitForDomChange` (DEPRECATED, use wait instead)
```typescript
function waitForDomChange(options?: {
@@ -167,20 +154,11 @@ container.setAttribute('data-cool', 'false')
*/
```
-Using
-[`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
-is more efficient than polling the DOM at regular intervals with `wait`. This
-library sets up a
-[`'mutationobserver-shim'`](https://github.com/megawac/MutationObserver.js) on
-the global `window` object for cross-platform compatibility with older browsers
-and the [`jsdom`](https://github.com/jsdom/jsdom/issues/639) that is usually
-used in Node-based tests.
-
The default `container` is the global `document`. Make sure the elements you
-wait for will be attached to it, or set a different `container`.
+wait for are descendants of `container`.
-The default `timeout` is `4500ms` which will keep you under
-[Jest's default timeout of `5000ms`](https://facebook.github.io/jest/docs/en/jest-object.html#jestsettimeouttimeout).
+The default `timeout` is `1000ms` which will keep you under
+[Jest's default timeout of `5000ms`](https://jestjs.io/docs/en/jest-object.html#jestsettimeouttimeout).
The default `mutationObserverOptions` is
`{subtree: true, childList: true, attributes: true, characterData: true}` which
@@ -188,10 +166,11 @@ will detect additions and removals of child elements (including text nodes) in
the `container` and any of its descendants. It will also detect attribute
changes.
-## `waitForElementToBeRemoved`
+
+## `waitForElement` (DEPRECATED, use `find*` queries or `wait`)
```typescript
-function waitForElementToBeRemoved(
+function waitForElement(
callback: () => T,
options?: {
container?: HTMLElement
@@ -201,54 +180,42 @@ function waitForElementToBeRemoved(
): Promise
```
-To wait for the removal of element(s) from the DOM you can use
-`waitForElementToBeRemoved`. The `waitForElementToBeRemoved` function is a small
-wrapper around the
+When in need to wait for DOM elements to appear, disappear, or change you can
+use `waitForElement`. The `waitForElement` function is a small wrapper around
+the
[`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver).
-The callback must return the pre-existing element or array of elements that are
-expected to be removed.
-
-Here is an example where the promise resolves with `true` because the element is
-removed:
+Here's a simple example:
```javascript
-const el = document.querySelector('div.getOuttaHere')
-
-waitForElementToBeRemoved(() =>
- document.querySelector('div.getOuttaHere')
-).then(() => console.log('Element no longer in DOM'))
-
-el.setAttribute('data-neat', true)
-// other mutations are ignored...
-
-el.parentElement.removeChild(el)
-// logs 'Element no longer in DOM'
+// ...
+// Wait until the callback does not throw an error and returns a truthy value. In this case, that means
+// it'll wait until we can get a form control with a label that matches "username".
+// The difference from `wait` is that rather than running your callback on
+// an interval, it's run as soon as there are DOM changes in the container
+// and returns the value returned by the callback.
+const usernameElement = await waitForElement(
+ () => getByLabelText(container, 'username'),
+ { container }
+)
+usernameElement.value = 'chucknorris'
+// ...
```
-`waitForElementToBeRemoved` will throw an error when the provided callback does
-not return an element.
+You can also wait for multiple elements at once:
```javascript
-waitForElementToBeRemoved(() => null).catch(err => console.log(err))
-
-// 'The callback function which was passed did not return an element
-// or non-empty array of elements.
-// waitForElementToBeRemoved requires that the element(s) exist
-// before waiting for removal.'
+const [usernameElement, passwordElement] = await waitForElement(
+ () => [
+ getByLabelText(container, 'username'),
+ getByLabelText(container, 'password'),
+ ],
+ { container }
+)
```
-Using
-[`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
-is more efficient than polling the DOM at regular intervals with `wait`. This
-library sets up a
-[`'mutationobserver-shim'`](https://github.com/megawac/MutationObserver.js) on
-the global `window` object for cross-platform compatibility with older browsers
-and the [`jsdom`](https://github.com/jsdom/jsdom/issues/639) that is usually
-used in Node-based tests.
-
The default `container` is the global `document`. Make sure the elements you
-wait for are descendants of `container`.
+wait for will be attached to it, or set a different `container`.
The default `timeout` is `4500ms` which will keep you under
[Jest's default timeout of `5000ms`](https://facebook.github.io/jest/docs/en/jest-object.html#jestsettimeouttimeout).
From 65abcf374d01eb4656e9afbda48ecfd7946bcdd4 Mon Sep 17 00:00:00 2001
From: Ben
Date: Mon, 16 Mar 2020 01:51:11 +0000
Subject: [PATCH 064/903] docs: remove `console.log` from `logRoles` example
(#404)
---
docs/dom-testing-library/api-helpers.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-helpers.md b/docs/dom-testing-library/api-helpers.md
index 1d3cc6cd4..7b7d45f1b 100644
--- a/docs/dom-testing-library/api-helpers.md
+++ b/docs/dom-testing-library/api-helpers.md
@@ -291,7 +291,7 @@ nav.innerHTML = `
Item 2
`
-console.log(logRoles(nav))
+logRoles(nav)
// navigation:
//
From f7518a6c25ec8353e732ec1dfe430819111c865b Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 15 Mar 2020 19:51:43 -0600
Subject: [PATCH 065/903] docs: add rockingskier as a contributor (#405)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index f00706346..469b8266f 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -567,6 +567,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "rockingskier",
+ "name": "Ben",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/681614?v=4",
+ "profile": "https://github.com/rockingskier",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index e61b94ab8..5db08d628 100644
--- a/README.md
+++ b/README.md
@@ -113,6 +113,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Dale French π
aw-davidson π
Benjamin Blackwood π
+ Ben π
From f1fa42ea41d4f528dd5d244fdf2bdececf4d259c Mon Sep 17 00:00:00 2001
From: Ben Monro
Date: Mon, 16 Mar 2020 11:20:40 -0700
Subject: [PATCH 066/903] update async docs (#406)
---
docs/dom-testing-library/api-async.md | 35 ++++++++++++++++++++-------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/docs/dom-testing-library/api-async.md b/docs/dom-testing-library/api-async.md
index 017aa8e3b..53a282fef 100644
--- a/docs/dom-testing-library/api-async.md
+++ b/docs/dom-testing-library/api-async.md
@@ -7,12 +7,12 @@ Several utilities are provided for dealing with asynchronous code. These can be
useful to wait for an element to appear or disappear in response to an action.
(See the [guide to testing disappearance](guide-disappearance.md).)
-All the async utils are built on top of `wait`.
+All the async utils are built on top of `waitFor`.
-## `wait`
+## `waitFor`
```typescript
-function wait(
+function waitFor(
callback: () => void,
options?: {
container?: HTMLElement
@@ -23,14 +23,14 @@ function wait(
): Promise
```
-When in need to wait for any period of time you can use `wait`, to wait for your
+When in need to wait for any period of time you can use `waitFor`, to wait for your
expectations to pass. Here's a simple example:
```javascript
// ...
// Wait until the callback does not throw an error. In this case, that means
// it'll wait until we can get a form control with a label that matches "username".
-await wait(() => expect(mockAPI).toHaveBeenCalledTimes(1))
+await waitFor(() => expect(mockAPI).toHaveBeenCalledTimes(1))
// ...
```
@@ -101,9 +101,26 @@ waitForElementToBeRemoved(() => getByText(/not here/i)).catch(err => console.log
// Error: The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.
```
-The options object is forwarded to `wait`.
+The options object is forwarded to `waitFor`.
+
+## `wait` (DEPRECATED, use waitFor instead)
+
+## `wait`
+
+```typescript
+function wait(
+ callback: () => void,
+ options?: {
+ container?: HTMLElement
+ timeout?: number
+ interval?: number
+ mutationObserverOptions?: MutationObserverInit
+ }
+): Promise
+```
+Previously, wait was a wrapper around wait-for-expect and used polling instead of a MutationObserver to look for changes. It is now an alias to waitFor and will be removed in a future release.
-## `waitForDomChange` (DEPRECATED, use wait instead)
+## `waitForDomChange` (DEPRECATED, use waitFor instead)
```typescript
function waitForDomChange(options?: {
@@ -167,7 +184,7 @@ the `container` and any of its descendants. It will also detect attribute
changes.
-## `waitForElement` (DEPRECATED, use `find*` queries or `wait`)
+## `waitForElement` (DEPRECATED, use `find*` queries or `waitFor`)
```typescript
function waitForElement(
@@ -191,7 +208,7 @@ Here's a simple example:
// ...
// Wait until the callback does not throw an error and returns a truthy value. In this case, that means
// it'll wait until we can get a form control with a label that matches "username".
-// The difference from `wait` is that rather than running your callback on
+// Previously, the difference from `wait` is that rather than running your callback on
// an interval, it's run as soon as there are DOM changes in the container
// and returns the value returned by the callback.
const usernameElement = await waitForElement(
From f439b7cd38421f13006941a5828c68a9b4fd52c2 Mon Sep 17 00:00:00 2001
From: Daniel Afonso <35337607+danieljcafonso@users.noreply.github.com>
Date: Wed, 25 Mar 2020 21:58:16 +0000
Subject: [PATCH 067/903] Update guide-disappearance.md (#412)
Update to mention `waitFor` as it will replace `wait` and change `waitForElement` example to use `findBy` query instead.
---
docs/guide-disappearance.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/docs/guide-disappearance.md b/docs/guide-disappearance.md
index da112c144..05be8acd7 100644
--- a/docs/guide-disappearance.md
+++ b/docs/guide-disappearance.md
@@ -17,12 +17,12 @@ test('movie title appears', async () => {
// element is initially not present...
// wait for appearance
- await wait(() => {
+ await waitFor(() => {
expect(getByText('the lion king')).toBeInTheDocument()
})
// wait for appearance and return the element
- const movie = await waitForElement(() => getByText('the lion king'))
+ const movie = await findByText('the lion king')
})
```
@@ -41,9 +41,9 @@ test('movie title no longer present in DOM', async () => {
Using
[`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
-is more efficient than polling the DOM at regular intervals with `wait`.
+is more efficient than polling the DOM at regular intervals with `waitFor`.
-The `wait` [async helper][async-api] function retries until the wrapped function
+The `waitFor` [async helper][async-api] function retries until the wrapped function
stops throwing an error. This can be used to assert that an element disappears
from the page.
@@ -52,7 +52,7 @@ test('movie title goes away', async () => {
// element is initially present...
// note use of queryBy instead of getBy to return null
// instead of throwing in the query itself
- await wait(() => {
+ await waitFor(() => {
expect(queryByText('i, robot')).not.toBeInTheDocument()
})
})
From 4e3d7ca4cf03b25100d44303bc78fb33036de32c Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Wed, 25 Mar 2020 15:58:39 -0600
Subject: [PATCH 068/903] docs: add danieljcafonso as a contributor (#413)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 3 +++
2 files changed, 12 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 469b8266f..c58069e4b 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -576,6 +576,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "danieljcafonso",
+ "name": "Daniel Afonso",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/35337607?v=4",
+ "profile": "https://github.com/danieljcafonso",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 5db08d628..0d2188714 100644
--- a/README.md
+++ b/README.md
@@ -115,6 +115,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Benjamin Blackwood π
Ben π
+
+ Daniel Afonso π
+
From a033a9f66e0fcafa25e0470b48de68b6e531771e Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Wed, 25 Mar 2020 16:06:10 -0600
Subject: [PATCH 069/903] Update api-queries.md
---
docs/dom-testing-library/api-queries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index ee34ba188..ea0138512 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -738,7 +738,7 @@ cy.getByTestId('custom-element').should('exist')
> and should be avoided if possible. That said, they are _way_ better than
> querying based on DOM structure or styling css class names. Learn more about
> `data-testid`s from the blog post
-> ["Making your UI tests resilient to change"](https://blog.kentcdodds.com/making-your-ui-tests-resilient-to-change-d37a6ee37269)
+> ["Making your UI tests resilient to change"](https://kentcdodds.com/blog/making-your-ui-tests-resilient-to-change)
#### Overriding `data-testid`
From c170ba4a71994632db90c806903600b3dea4ebb8 Mon Sep 17 00:00:00 2001
From: Noman Gul
Date: Thu, 26 Mar 2020 09:01:20 +0500
Subject: [PATCH 070/903] fix: add React import statement (#414)
added React import statement because we are using JSX... otherwise, it was throwing an error
---
docs/react-testing-library/setup.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/docs/react-testing-library/setup.md b/docs/react-testing-library/setup.md
index 6a18df37d..a142df8b0 100644
--- a/docs/react-testing-library/setup.md
+++ b/docs/react-testing-library/setup.md
@@ -36,6 +36,7 @@ The example below sets up data providers using the
```js
// test-utils.js
+import React from "react"
import { render } from '@testing-library/react'
import { ThemeProvider } from 'my-ui-lib'
import { TranslationProvider } from 'my-i18n-lib'
From 21cc1b0e09f4b629b830eea6933ccf5fcc5afbb0 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Wed, 25 Mar 2020 22:01:51 -0600
Subject: [PATCH 071/903] docs: add NomanGul as a contributor (#415)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index c58069e4b..99f6e74f5 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -585,6 +585,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "NomanGul",
+ "name": "Noman Gul",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/39244918?v=4",
+ "profile": "https://dev.to/nomangul",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 0d2188714..5e27f8e8b 100644
--- a/README.md
+++ b/README.md
@@ -117,6 +117,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Daniel Afonso π
+ Noman Gul π
From 3c475bba7ed63c3a089dad0e0a0b944e71dc3d23 Mon Sep 17 00:00:00 2001
From: Bo Vandersteene
Date: Fri, 27 Mar 2020 21:30:45 +0100
Subject: [PATCH 072/903] Fix code example on angular examples.md (#407)
Add brackets around import { CounterComponent } from './counter.component.ts'
---
docs/angular-testing-library/examples.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/angular-testing-library/examples.md b/docs/angular-testing-library/examples.md
index c94f191a2..966d09fc0 100644
--- a/docs/angular-testing-library/examples.md
+++ b/docs/angular-testing-library/examples.md
@@ -36,7 +36,7 @@ counter.component.spec.ts
```typescript
import { render } from '@testing-library/angular'
-import CounterComponent from './counter.component.ts'
+import { CounterComponent } from './counter.component.ts'
describe('Counter', () => {
test('should render counter', async () => {
From cf02de5377b77f073d239a60f13a110afda17520 Mon Sep 17 00:00:00 2001
From: Zachary Davis
Date: Fri, 27 Mar 2020 16:32:36 -0400
Subject: [PATCH 073/903] Update example-intro to use the screen function
(#396)
* Update example-intro to use the screen function
* Remove container, asFragment from example-intro
---
docs/react-testing-library/example-intro.md | 29 +++++++++------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/docs/react-testing-library/example-intro.md b/docs/react-testing-library/example-intro.md
index 06b7a1bdf..0e610f82c 100644
--- a/docs/react-testing-library/example-intro.md
+++ b/docs/react-testing-library/example-intro.md
@@ -11,7 +11,7 @@ See the following sections for a detailed breakdown of the test
```jsx
// __tests__/fetch.test.js
import React from 'react'
-import { render, fireEvent, waitForElement } from '@testing-library/react'
+import { render, fireEvent, waitForElement, screen } from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'
import axiosMock from 'axios'
import Fetch from '../fetch'
@@ -20,20 +20,20 @@ jest.mock('axios')
test('loads and displays greeting', async () => {
const url = '/greeting'
- const { getByText, getByRole } = render( )
+ render( )
axiosMock.get.mockResolvedValueOnce({
data: { greeting: 'hello there' },
})
- fireEvent.click(getByText('Load Greeting'))
+ fireEvent.click(screen.getByText('Load Greeting'))
- const greetingTextNode = await waitForElement(() => getByRole('heading'))
+ await waitForElement(() => screen.getByRole('heading'))
expect(axiosMock.get).toHaveBeenCalledTimes(1)
expect(axiosMock.get).toHaveBeenCalledWith(url)
- expect(getByRole('heading')).toHaveTextContent('hello there')
- expect(getByRole('button')).toHaveAttribute('disabled')
+ expect(screen.getByRole('heading')).toHaveTextContent('hello there')
+ expect(screen.getByRole('button')).toHaveAttribute('disabled')
})
```
@@ -48,7 +48,7 @@ test('loads and displays greeting', async () => {
import React from 'react'
// import react-testing methods
-import { render, fireEvent, waitForElement } from '@testing-library/react'
+import { render, fireEvent, waitForElement, screen } from '@testing-library/react'
// add custom jest matchers from jest-dom
import '@testing-library/jest-dom/extend-expect'
@@ -70,14 +70,11 @@ test('loads and displays greeting', async () => {
### Arrange
-The [`render`](./api#render) method renders a React element into the DOM and
-returns utility functions for testing the component.
+The [`render`](./api#render) method renders a React element into the DOM and returns utility functions for testing the component.
```jsx
const url = '/greeting'
-const { getByText, getByRole, container, asFragment } = render(
-
-)
+const { container, asFragment } = render( )
```
### Act
@@ -96,9 +93,9 @@ fireEvent.click(getByText('Load Greeting'))
// the component calls setState and re-renders.
// `waitForElement` waits until the callback doesn't throw an error
-const greetingTextNode = await waitForElement(() =>
+await waitForElement(() =>
// getByRole throws an error if it cannot find an element
- getByRole('heading')
+ screen.getByRole('heading')
)
```
@@ -138,8 +135,8 @@ export default function Fetch({ url }) {
```jsx
expect(axiosMock.get).toHaveBeenCalledTimes(1)
expect(axiosMock.get).toHaveBeenCalledWith(url)
-expect(getByRole('heading')).toHaveTextContent('hello there')
-expect(getByRole('button')).toHaveAttribute('disabled')
+expect(screen.getByRole('heading')).toHaveTextContent('hello there')
+expect(screen.getByRole('button')).toHaveAttribute('disabled')
// snapshots work great with regular DOM nodes!
expect(container).toMatchInlineSnapshot(`
From 2fdf8442d18db4651c3aa1f0c45f0fd4c7918a77 Mon Sep 17 00:00:00 2001
From: Ned Schwartz
Date: Fri, 27 Mar 2020 18:25:09 -0400
Subject: [PATCH 074/903] Updates clientScript instructions to use module
(#411)
* Updates clientScript instructions to use module
module is preferable to abs file path as it works with workspaces etc.
* Fixes missing brackets around module
---
docs/testcafe-testing-library/intro.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/testcafe-testing-library/intro.md b/docs/testcafe-testing-library/intro.md
index f6e7694c9..f5a39e5fb 100644
--- a/docs/testcafe-testing-library/intro.md
+++ b/docs/testcafe-testing-library/intro.md
@@ -27,7 +27,7 @@ Add the following to your .testcaferc.json file:
```json
"clientScripts": [
- "./node_modules/@testing-library/dom/dist/@testing-library/dom.umd.js"
+ { "module": "@testing-library/dom/dist/@testing-library/dom.umd.js" }
],
```
From 341f41e4e8b2062ebf7ec7a2f3b5324980fb4d14 Mon Sep 17 00:00:00 2001
From: Rafael Souza
Date: Sat, 28 Mar 2020 12:58:10 -0300
Subject: [PATCH 075/903] Replace waitForElement to waitFor (#416)
---
docs/react-testing-library/example-intro.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/docs/react-testing-library/example-intro.md b/docs/react-testing-library/example-intro.md
index 0e610f82c..b5554346b 100644
--- a/docs/react-testing-library/example-intro.md
+++ b/docs/react-testing-library/example-intro.md
@@ -11,7 +11,7 @@ See the following sections for a detailed breakdown of the test
```jsx
// __tests__/fetch.test.js
import React from 'react'
-import { render, fireEvent, waitForElement, screen } from '@testing-library/react'
+import { render, fireEvent, waitFor, screen } from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'
import axiosMock from 'axios'
import Fetch from '../fetch'
@@ -28,7 +28,7 @@ test('loads and displays greeting', async () => {
fireEvent.click(screen.getByText('Load Greeting'))
- await waitForElement(() => screen.getByRole('heading'))
+ await waitFor(() => screen.getByRole('heading'))
expect(axiosMock.get).toHaveBeenCalledTimes(1)
expect(axiosMock.get).toHaveBeenCalledWith(url)
@@ -48,7 +48,7 @@ test('loads and displays greeting', async () => {
import React from 'react'
// import react-testing methods
-import { render, fireEvent, waitForElement, screen } from '@testing-library/react'
+import { render, fireEvent, waitFor, screen } from '@testing-library/react'
// add custom jest matchers from jest-dom
import '@testing-library/jest-dom/extend-expect'
@@ -91,9 +91,9 @@ fireEvent.click(getByText('Load Greeting'))
// Wait until the mocked `get` request promise resolves and
// the component calls setState and re-renders.
-// `waitForElement` waits until the callback doesn't throw an error
+// `waitFor` waits until the callback doesn't throw an error
-await waitForElement(() =>
+await waitFor(() =>
// getByRole throws an error if it cannot find an element
screen.getByRole('heading')
)
From e5fcd43c159fb24fcd1773f46d325fd276b3d044 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sat, 28 Mar 2020 09:58:50 -0600
Subject: [PATCH 076/903] docs: add rafaelangical as a contributor (#417)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 99f6e74f5..0096a0b81 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -594,6 +594,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "rafaelangical",
+ "name": "Rafael Souza",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/20307803?v=4",
+ "profile": "http://rafatech.tk/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 5e27f8e8b..1013f12ec 100644
--- a/README.md
+++ b/README.md
@@ -118,6 +118,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Daniel Afonso π
Noman Gul π
+ Rafael Souza π
From cfecbffc56eea35a5e620806fc3caa46af9ca6b2 Mon Sep 17 00:00:00 2001
From: Pavel Pustovalov
Date: Thu, 2 Apr 2020 00:50:57 +0300
Subject: [PATCH 077/903] Sync docs with latest dom-testing-library (#418)
---
docs/dom-testing-library/example-intro.md | 4 ++--
docs/example-react-router.md | 18 +++++++++++-------
docs/pptr-testing-library/intro.md | 2 +-
3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/docs/dom-testing-library/example-intro.md b/docs/dom-testing-library/example-intro.md
index 1ec820d90..923f27e6e 100644
--- a/docs/dom-testing-library/example-intro.md
+++ b/docs/dom-testing-library/example-intro.md
@@ -14,7 +14,7 @@ import {
queryByTestId,
// Tip: all queries are also exposed on an object
// called "queries" which you could import here as well
- wait,
+ waitFor,
} from '@testing-library/dom'
// adds special assertions like toHaveTextContent
import '@testing-library/jest-dom/extend-expect'
@@ -57,7 +57,7 @@ test('examples of some things', async () => {
// Get elements by their text, just like a real user does.
getByText(container, 'Print Username').click()
- await wait(() =>
+ await waitFor(() =>
expect(queryByTestId(container, 'printed-username')).toBeTruthy()
)
diff --git a/docs/example-react-router.md b/docs/example-react-router.md
index eedee0acf..efddacb7b 100644
--- a/docs/example-react-router.md
+++ b/docs/example-react-router.md
@@ -87,20 +87,23 @@ test('rendering a component that uses withRouter', () => {
## Reducing boilerplate
-1. You can use the `wrapper` option to wrap a `MemoryRouter` around the component you want to render (`MemoryRouter` works when you don't need access to the history object itself in the test, but just need the components to be able to render and navigate).
+1. You can use the `wrapper` option to wrap a `MemoryRouter` around the
+ component you want to render (`MemoryRouter` works when you don't need access
+ to the history object itself in the test, but just need the components to be
+ able to render and navigate).
```jsx
import { MemoryRouter } from 'react-router-dom'
test('full app rendering/navigating', () => {
- const { container, getByText } = render( , {wrapper: MemoryRouter})
+ const { container, getByText } = render( , { wrapper: MemoryRouter })
// verify page content for expected route
expect(getByRole('heading')).toMatch('Home')
})
```
-2. If you find yourself adding Router components to your tests a lot, you may want to create
-a helper function that wraps around `render`.
+2. If you find yourself adding Router components to your tests a lot, you may
+ want to create a helper function that wraps around `render`.
```jsx
// test utils file
@@ -111,9 +114,11 @@ function renderWithRouter(
history = createMemoryHistory({ initialEntries: [route] }),
} = {}
) {
- const Wrapper = ({children}) => {children}
+ const Wrapper = ({ children }) => (
+ {children}
+ )
return {
- ...render(ui, {wrapper: Wrapper}),
+ ...render(ui, { wrapper: Wrapper }),
// adding `history` to the returned utilities to allow us
// to reference it in our tests (just try to avoid using
// this to test implementation details).
@@ -137,4 +142,3 @@ test('rendering a component that uses withRouter', () => {
expect(getByTestId('location-display')).toHaveTextContent(route)
})
```
-
diff --git a/docs/pptr-testing-library/intro.md b/docs/pptr-testing-library/intro.md
index b3956eedb..8c41ee63d 100644
--- a/docs/pptr-testing-library/intro.md
+++ b/docs/pptr-testing-library/intro.md
@@ -32,7 +32,7 @@ const $email = await getByLabelText($form, 'Email')
// interact with puppeteer like usual
await $email.type('pptr@example.com')
// waiting works too!
-await wait(() => getByText('Loading...'))
+await waitFor(() => getByText('Loading...'))
```
A little too un-puppeteer for you? You can attach all the `DOM Testing Library`
From b83c4437d47e76433412118229517326d4c323d3 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Wed, 1 Apr 2020 15:51:25 -0600
Subject: [PATCH 078/903] docs: add pustovalov as a contributor (#420)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 0096a0b81..c84c96424 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -603,6 +603,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "pustovalov",
+ "name": "Pavel Pustovalov",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/1568885?v=4",
+ "profile": "http://pustovalov.dev/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 1013f12ec..cbe8aa3aa 100644
--- a/README.md
+++ b/README.md
@@ -119,6 +119,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Daniel Afonso π
Noman Gul π
Rafael Souza π
+ Pavel Pustovalov π
From abd90096099cf48df2a83ec69693183573efede8 Mon Sep 17 00:00:00 2001
From: Robbie
Date: Thu, 2 Apr 2020 14:03:11 -0600
Subject: [PATCH 079/903] docs: Fix event link to event map file (#423)
---
docs/dom-testing-library/api-events.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-events.md b/docs/dom-testing-library/api-events.md
index 981391afe..cf4a0b35f 100644
--- a/docs/dom-testing-library/api-events.md
+++ b/docs/dom-testing-library/api-events.md
@@ -29,7 +29,7 @@ fireEvent[eventName](node: HTMLElement, eventProperties: Object)
```
Convenience methods for firing DOM events. Check out
-[src/events.js](https://github.com/testing-library/dom-testing-library/blob/master/src/events.js)
+[src/event-map.js](https://github.com/testing-library/dom-testing-library/blob/master/src/event-map.js)
for a full list as well as default `eventProperties`.
```javascript
From d218eac001ac0b082bd80b91092a97561b47f8b8 Mon Sep 17 00:00:00 2001
From: Dyma <32801166+dymafr@users.noreply.github.com>
Date: Sun, 5 Apr 2020 22:56:07 +0200
Subject: [PATCH 080/903] findBy / findAllBy default timeout (#425)
findBy / findAllBy default timeout is 1000ms and not 450ms
see:
https://github.com/testing-library/dom-testing-library/blob/1b711a4a0143b532dc8258f9ceac1a1b36557ce0/src/config.js#L8
https://github.com/testing-library/dom-testing-library/blob/672f2316d49609572857e7de80251eb052c9cbd1/src/wait-for.js#L15
Thanks for your awesome work!
---
docs/dom-testing-library/api-queries.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index ea0138512..eca60651a 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -34,7 +34,7 @@ return an empty array (`[]`) if no elements match.
`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 or if
-more than one element is found after a default timeout of `4500`ms. If you need
+more than one element is found after a default timeout of `1000`ms. If you need
to find more than one element, then use `findAllBy`.
> Note, this is a simple combination of `getBy*` queries and
@@ -46,7 +46,7 @@ to find more than one element, then use `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.
+if no elements are found after a default timeout of `1000`ms.
## Options
From 560e372917bc6c7d021bc6415e16f1ea718bfd00 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 5 Apr 2020 14:56:38 -0600
Subject: [PATCH 081/903] docs: add dymafr as a contributor (#426)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index c84c96424..688a91467 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -612,6 +612,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "dymafr",
+ "name": "Dyma",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/32801166?v=4",
+ "profile": "https://github.com/dymafr",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index cbe8aa3aa..8a9e00acf 100644
--- a/README.md
+++ b/README.md
@@ -120,6 +120,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Noman Gul π
Rafael Souza π
Pavel Pustovalov π
+ Dyma π
From 901e9077aade9cbe392eb1a6923a000d67bc5652 Mon Sep 17 00:00:00 2001
From: Matan Borenkraout
Date: Mon, 6 Apr 2020 20:13:56 +0300
Subject: [PATCH 082/903] Update React Redux recipe to use custom render with
wrapper (#424)
* Chore: Update react-redux recipe to use custom render with wrapper
* Review fixes, removed the h1 and refactored the class component to a functional one
* Added the export and updated the comment after kent's review
---
docs/example-react-redux.md | 106 +++++++++++++++++++++---------------
1 file changed, 61 insertions(+), 45 deletions(-)
diff --git a/docs/example-react-redux.md b/docs/example-react-redux.md
index 4687189e8..c759ec3ae 100644
--- a/docs/example-react-redux.md
+++ b/docs/example-react-redux.md
@@ -8,27 +8,25 @@ title: React Redux
import React from 'react'
import { connect } from 'react-redux'
-class Counter extends React.Component {
- increment = () => {
- this.props.dispatch({ type: 'INCREMENT' })
+const Counter = ({ dispatch, count }) => {
+ const increment = () => {
+ dispatch({ type: 'INCREMENT' })
}
- decrement = () => {
- this.props.dispatch({ type: 'DECREMENT' })
+ const decrement = () => {
+ dispatch({ type: 'DECREMENT' })
}
- render() {
- return (
+ return (
+
+
Counter
-
Counter
-
- -
- {this.props.count}
- +
-
+
-
+
{count}
+
+
- )
- }
+
+ )
}
export default connect(state => ({ count: state.count }))(Counter)
@@ -58,58 +56,76 @@ export function reducer(state = initialState, action) {
}
```
-Now here's what your test will look like:
+To test our connected component we can create a custom `render` function using
+the `wrapper` option as explained in the
+[setup](./react-testing-library/setup.md) page.
+Our custom `render` function can look like this:
-```jsx
-// counter.test.js
+```js
+// test-utils.js
import React from 'react'
+import { render as rtlRender } from '@testing-library/react'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
-import { render, fireEvent } from '@testing-library/react'
-import '@testing-library/jest-dom/extend-expect'
-import { initialState, reducer } from './reducer.js'
-import Counter from './counter.js'
-
-// this is a handy function that I normally make available for all my tests
-// that deal with connected components.
-// you can provide initialState for the entire store that the ui is rendered with
-function renderWithRedux(
+function render(
ui,
- { initialState, store = createStore(reducer, initialState) } = {}
+ {
+ initialState,
+ store = createStore(reducer, initialState),
+ ...renderOptions
+ } = {}
) {
- return {
- ...render({ui} ),
- // adding `store` to the returned utilities to allow us
- // to reference it in our tests (just try to avoid using
- // this to test implementation details).
- store,
+ function Wrapper({ children }) {
+ return {children}
}
+ return rtlRender(ui, { wrapper: Wrapper, ...renderOptions })
}
+// re-export everything
+export * from '@testing-library/react'
+
+// override render method
+export { render }
+```
+
+```jsx
+// counter.test.js
+import React from 'react'
+import { createStore } from 'redux'
+import { Provider } from 'react-redux'
+import { } from '@testing-library/react'
+// We're using our own custom render function and not RTL's render
+// our custom utils also re-export everything from RTL
+// so we can import fireEvent and screen here as well
+import { render, fireEvent, screen } from './test-utils.js
+import '@testing-library/jest-dom/extend-expect'
+import { initialState, reducer } from './reducer.js'
+import Counter from './counter.js'
+
test('can render with redux with defaults', () => {
- const { getByTestId, getByText } = renderWithRedux( )
- fireEvent.click(getByText('+'))
- expect(getByTestId('count-value')).toHaveTextContent('1')
+ renderWithRedux( )
+ fireEvent.click(screen.getByText('+'))
+ expect(screen.getByTestId('count-value')).toHaveTextContent('1')
})
test('can render with redux with custom initial state', () => {
- const { getByTestId, getByText } = renderWithRedux( , {
+ renderWithRedux( , {
initialState: { count: 3 },
})
- fireEvent.click(getByText('-'))
- expect(getByTestId('count-value')).toHaveTextContent('2')
+ fireEvent.click(screen.getByText('-'))
+ expect(screen.getByTestId('count-value')).toHaveTextContent('2')
})
test('can render with redux with custom store', () => {
// this is a silly store that can never be changed
const store = createStore(() => ({ count: 1000 }))
- const { getByTestId, getByText } = renderWithRedux( , {
+ renderWithRedux( , {
store,
})
- fireEvent.click(getByText('+'))
- expect(getByTestId('count-value')).toHaveTextContent('1000')
- fireEvent.click(getByText('-'))
- expect(getByTestId('count-value')).toHaveTextContent('1000')
+ fireEvent.click(screen.getByText('+'))
+ expect(screen.getByTestId('count-value')).toHaveTextContent('1000')
+ fireEvent.click(screen.getByText('-'))
+ expect(screen.getByTestId('count-value')).toHaveTextContent('1000')
})
```
From 99c9fcde6b8bc5ff11e695452b994fbc9b7acbd5 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Mon, 6 Apr 2020 11:15:09 -0600
Subject: [PATCH 083/903] docs: add MatanBobi as a contributor (#429)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 688a91467..93f84f777 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -621,6 +621,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "MatanBobi",
+ "name": "Matan Borenkraout",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/12711091?v=4",
+ "profile": "https://twitter.com/matan_bobi",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 8a9e00acf..f4dfe7a02 100644
--- a/README.md
+++ b/README.md
@@ -121,6 +121,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Rafael Souza π
Pavel Pustovalov π
Dyma π
+ Matan Borenkraout π
From a2f39fc405445488296e7accdac8e2f024c84fff Mon Sep 17 00:00:00 2001
From: Dyma <32801166+dymafr@users.noreply.github.com>
Date: Mon, 6 Apr 2020 21:21:39 +0200
Subject: [PATCH 084/903] Update api-events.md (#428)
code are wrong, see:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values
charCode and keyCode are deprecated and should not be used any more:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/charCode
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
---
docs/dom-testing-library/api-events.md | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/docs/dom-testing-library/api-events.md b/docs/dom-testing-library/api-events.md
index cf4a0b35f..e626f1d95 100644
--- a/docs/dom-testing-library/api-events.md
+++ b/docs/dom-testing-library/api-events.md
@@ -64,18 +64,9 @@ fireEvent.change(getByLabelText(/picture/i), {
element in the DOM and the key you want to fire.
```javascript
-fireEvent.keyDown(domNode, { key: 'Enter', code: 13 })
+fireEvent.keyDown(domNode, { key: 'Enter', code: 'Enter' })
-// note: you should set the charCode or it will be fallback to 0
-// will fire a KeyboardEvent with charCode = 13
-fireEvent.keyDown(domNode, { key: 'Enter', code: 13 })
-
-// If using event.which, be sure to set the keyCode or it will be fallback to 0
-// will fire a KeyboardEvent with expected which = 13
-fireEvent.keyDown(domNode, { key: 'Enter', keyCode: 13 })
-
-// will fire a KeyboardEvent with charCode = 65
-fireEvent.keyDown(domNode, { key: 'A', code: 65, charCode: 65 })
+fireEvent.keyDown(domNode, { key: 'A', code: 'KeyQ' })
```
You can find out which key code to use at
From 336c1710dbc5121bdfc6136852234ea228c79e97 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Mon, 6 Apr 2020 17:09:53 -0600
Subject: [PATCH 085/903] add react native shortcut
---
netlify.toml | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/netlify.toml b/netlify.toml
index e0aba7961..e4ed55f59 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -55,6 +55,13 @@
status = 301
force = true
+# React Native landing page to home page
+[[redirects]]
+ from = "https://testing-library.com/react-native/"
+ to = "https://testing-library.com/docs/native-testing-library/intro"
+ status = 301
+ force = true
+
# Cypress landing page to home page
[[redirects]]
from = "https://testing-library.com/cypress/"
From 8e70c0c26865817359ca90ea04e4e4b32b5cb497 Mon Sep 17 00:00:00 2001
From: Matan Borenkraout
Date: Tue, 7 Apr 2020 09:51:18 +0300
Subject: [PATCH 086/903] Fix: Remove the unnecessary empty import from
React-Redux example
---
docs/example-react-redux.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/docs/example-react-redux.md b/docs/example-react-redux.md
index c759ec3ae..cf378177e 100644
--- a/docs/example-react-redux.md
+++ b/docs/example-react-redux.md
@@ -94,7 +94,6 @@ export { render }
import React from 'react'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
-import { } from '@testing-library/react'
// We're using our own custom render function and not RTL's render
// our custom utils also re-export everything from RTL
// so we can import fireEvent and screen here as well
From 84afd3febd425c6c7e4584b3fd0e89e7fd4adb15 Mon Sep 17 00:00:00 2001
From: Matan Borenkraout
Date: Tue, 7 Apr 2020 09:54:23 +0300
Subject: [PATCH 087/903] Use the render function isntead of renderWithRedux as
used to
---
docs/example-react-redux.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/example-react-redux.md b/docs/example-react-redux.md
index cf378177e..1a22e9b5a 100644
--- a/docs/example-react-redux.md
+++ b/docs/example-react-redux.md
@@ -103,13 +103,13 @@ import { initialState, reducer } from './reducer.js'
import Counter from './counter.js'
test('can render with redux with defaults', () => {
- renderWithRedux( )
+ render( )
fireEvent.click(screen.getByText('+'))
expect(screen.getByTestId('count-value')).toHaveTextContent('1')
})
test('can render with redux with custom initial state', () => {
- renderWithRedux( , {
+ render( , {
initialState: { count: 3 },
})
fireEvent.click(screen.getByText('-'))
@@ -119,7 +119,7 @@ test('can render with redux with custom initial state', () => {
test('can render with redux with custom store', () => {
// this is a silly store that can never be changed
const store = createStore(() => ({ count: 1000 }))
- renderWithRedux( , {
+ render( , {
store,
})
fireEvent.click(screen.getByText('+'))
From 27a43773324b5aff659b81b076136ded1a0b60f6 Mon Sep 17 00:00:00 2001
From: Matan Borenkraout
Date: Tue, 7 Apr 2020 10:03:12 +0300
Subject: [PATCH 088/903] Remove unnecessary Provider import
---
docs/example-react-redux.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/docs/example-react-redux.md b/docs/example-react-redux.md
index 1a22e9b5a..a1f66490a 100644
--- a/docs/example-react-redux.md
+++ b/docs/example-react-redux.md
@@ -93,7 +93,6 @@ export { render }
// counter.test.js
import React from 'react'
import { createStore } from 'redux'
-import { Provider } from 'react-redux'
// We're using our own custom render function and not RTL's render
// our custom utils also re-export everything from RTL
// so we can import fireEvent and screen here as well
From 9b4e87c1651aa2095c4dec76ad5032330365ad62 Mon Sep 17 00:00:00 2001
From: Matan Borenkraout
Date: Tue, 7 Apr 2020 10:11:22 +0300
Subject: [PATCH 089/903] Import the reducer on the correct place
---
docs/example-react-redux.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/example-react-redux.md b/docs/example-react-redux.md
index a1f66490a..d3701ba73 100644
--- a/docs/example-react-redux.md
+++ b/docs/example-react-redux.md
@@ -67,6 +67,7 @@ import React from 'react'
import { render as rtlRender } from '@testing-library/react'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
+import { initialState, reducer } from './reducer'
function render(
ui,
@@ -96,10 +97,9 @@ import { createStore } from 'redux'
// We're using our own custom render function and not RTL's render
// our custom utils also re-export everything from RTL
// so we can import fireEvent and screen here as well
-import { render, fireEvent, screen } from './test-utils.js
+import { render, fireEvent, screen } from './test-utils'
import '@testing-library/jest-dom/extend-expect'
-import { initialState, reducer } from './reducer.js'
-import Counter from './counter.js'
+import Counter from './counter'
test('can render with redux with defaults', () => {
render( )
From cdfafdb423b9168dc7ec7be5155a2bd52f5d1e8f Mon Sep 17 00:00:00 2001
From: Matan Borenkraout
Date: Tue, 7 Apr 2020 10:12:58 +0300
Subject: [PATCH 090/903] Fix initialState
---
docs/example-react-redux.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/example-react-redux.md b/docs/example-react-redux.md
index d3701ba73..c76744578 100644
--- a/docs/example-react-redux.md
+++ b/docs/example-react-redux.md
@@ -67,12 +67,12 @@ import React from 'react'
import { render as rtlRender } from '@testing-library/react'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
-import { initialState, reducer } from './reducer'
+import { initialState as reducerInitialState, reducer } from './reducer'
function render(
ui,
{
- initialState,
+ initialState = reducerInitialState,
store = createStore(reducer, initialState),
...renderOptions
} = {}
From fb009d2e59f6a5ca9011f19351d1534fb046bef6 Mon Sep 17 00:00:00 2001
From: Matan Borenkraout
Date: Tue, 7 Apr 2020 10:24:22 +0300
Subject: [PATCH 091/903] Remove the this from the functional component
---
docs/example-react-redux.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/example-react-redux.md b/docs/example-react-redux.md
index c76744578..bd93e6caf 100644
--- a/docs/example-react-redux.md
+++ b/docs/example-react-redux.md
@@ -21,9 +21,9 @@ const Counter = ({ dispatch, count }) => {
Counter
- -
+ -
{count}
- +
+ +
)
From 6f657c514f0eed19a3b634e7f9457800810b6a63 Mon Sep 17 00:00:00 2001
From: timrobinson33 <57178390+timrobinson33@users.noreply.github.com>
Date: Tue, 7 Apr 2020 14:57:34 +0100
Subject: [PATCH 092/903] explain how to update wait to waitFor (#432)
added information for anyone trying to migrate an existing parameterless wait call
---
docs/dom-testing-library/api-async.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/dom-testing-library/api-async.md b/docs/dom-testing-library/api-async.md
index 53a282fef..5272e04ad 100644
--- a/docs/dom-testing-library/api-async.md
+++ b/docs/dom-testing-library/api-async.md
@@ -105,8 +105,6 @@ The options object is forwarded to `waitFor`.
## `wait` (DEPRECATED, use waitFor instead)
-## `wait`
-
```typescript
function wait(
callback: () => void,
@@ -120,6 +118,8 @@ function wait(
```
Previously, wait was a wrapper around wait-for-expect and used polling instead of a MutationObserver to look for changes. It is now an alias to waitFor and will be removed in a future release.
+Unlike wait, the callback parameter is mandatory in waitFor. Although you can migrate an existing `wait()` call to `waitFor( () => {} )`, it is considered bad practice to use an empty callback because it will make the tests more fragile.
+
## `waitForDomChange` (DEPRECATED, use waitFor instead)
```typescript
From f94d2c3e4341d247a74e3cb742098bd5b66ee508 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 7 Apr 2020 08:00:55 -0600
Subject: [PATCH 093/903] docs: add timrobinson33 as a contributor (#433)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 93f84f777..4961f8ec1 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -630,6 +630,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "timrobinson33",
+ "name": "timrobinson33",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/57178390?v=4",
+ "profile": "https://github.com/timrobinson33",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index f4dfe7a02..cff558253 100644
--- a/README.md
+++ b/README.md
@@ -122,6 +122,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Pavel Pustovalov π
Dyma π
Matan Borenkraout π
+ timrobinson33 π
From 34c148920f43840f4c512df7962fd6da765073ae Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Tue, 7 Apr 2020 10:39:43 -0600
Subject: [PATCH 094/903] Update all query references to screen (#434)
This is recommended and works better across framework implementations so there should be less confusion.
---
docs/dom-testing-library/api-queries.md | 165 +++++++++++-------------
1 file changed, 76 insertions(+), 89 deletions(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index eca60651a..7db41f461 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -40,7 +40,7 @@ to find more than one element, then use `findAllBy`.
> 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)`)
+> `screen.findByText('text', queryOptions, waitForElementOptions)`)
### findAllBy
@@ -111,7 +111,7 @@ screen.debug(screen.getAllByText('multi-test'))
> a pre-bound version of these queries when you render your components with them
> which means you do not have to provide a container. In addition, if you just
> want to query `document.body` then you can use the [`screen`](#screen) export
-> as demonstrated above.
+> as demonstrated above (using `screen` is recommended).
### `ByLabelText`
@@ -120,7 +120,7 @@ screen.debug(screen.getAllByText('multi-test'))
```typescript
getByLabelText(
- container: HTMLElement,
+ container: HTMLElement, // if you're using `screen`, then skip this argument
text: TextMatch,
options?: {
selector?: string = '*',
@@ -163,20 +163,19 @@ The example below will find the input node for the following DOM structures:
```javascript
-import { getByLabelText } from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
-const container = document.body
-const inputNode = getByLabelText(container, 'Username')
+const inputNode = screen.getByLabelText('Username')
```
```js
-import { render } from '@testing-library/react'
+import { render, screen } from '@testing-library/react'
-const { getByLabelText } = render( )
+render( )
-const inputNode = getByLabelText('username')
+const inputNode = screen.getByLabelText('username')
```
@@ -199,10 +198,7 @@ If it is important that you query an actual `` element you can provide a
```
```js
-const container = document.body
-const inputNode = getByLabelText(container, 'Username', {
- selector: 'input',
-})
+const inputNode = screen.getByLabelText('Username', {selector: 'input'})
```
### `ByPlaceholderText`
@@ -212,7 +208,7 @@ const inputNode = getByLabelText(container, 'Username', {
```typescript
getByPlaceholderText(
- container: HTMLElement,
+ container: HTMLElement, // if you're using `screen`, then skip this argument
text: TextMatch,
options?: {
exact?: boolean = true,
@@ -232,19 +228,18 @@ matches the given [`TextMatch`](#textmatch).
```js
-import { getByPlaceholderText } from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
-const container = document.body
-const inputNode = getByPlaceholderText(container, 'Username')
+const inputNode = screen.getByPlaceholderText('Username')
```
```js
-import { render } from '@testing-library/react'
+import { render, screen } from '@testing-library/react'
-const { getByPlaceholderText } = render( )
-const inputNode = getByPlaceholderText('Username')
+render( )
+const inputNode = screen.getByPlaceholderText('Username')
```
@@ -267,7 +262,7 @@ cy.getByPlaceholderText('Username').should('exist')
```typescript
getByText(
- container: HTMLElement,
+ container: HTMLElement, // if you're using `screen`, then skip this argument
text: TextMatch,
options?: {
selector?: string = '*',
@@ -289,19 +284,18 @@ matching the given [`TextMatch`](#textmatch).
```js
-import { getByText } from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
-const container = document.body
-const aboutAnchorNode = getByText(container, /about/i)
+const aboutAnchorNode = screen.getByText(/about/i)
```
```js
-import { render } from '@testing-library/react'
+import { render, screen } from '@testing-library/react'
-const { getByText } = render( )
-const aboutAnchorNode = getByText(/about/i)
+render( )
+const aboutAnchorNode = screen.getByText(/about/i)
```
@@ -339,7 +333,7 @@ If you'd rather disable this behavior, set `ignore` to `false`.
```typescript
getByAltText(
- container: HTMLElement,
+ container: HTMLElement, // if you're using `screen`, then skip this argument
text: TextMatch,
options?: {
exact?: boolean = true,
@@ -365,19 +359,18 @@ as it's deprecated).
```js
-import { getByAltText } from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
-const container = document.body
-const incrediblesPosterImg = getByAltText(container, /incredibles.*? poster/i)
+const incrediblesPosterImg = screen.getByAltText(/incredibles.*? poster/i)
```
```js
-import { render } from '@testing-library/react'
+import { render, screen } from '@testing-library/react'
-const { getByAltText } = render( )
-const incrediblesPosterImg = getByAltText(/incredibles.*? poster/i)
+render( )
+const incrediblesPosterImg = screen.getByAltText(/incredibles.*? poster/i)
```
@@ -395,7 +388,7 @@ cy.getByAltText(/incredibles.*? poster/i).should('exist')
```typescript
getByTitle(
- container: HTMLElement,
+ container: HTMLElement, // if you're using `screen`, then skip this argument
title: TextMatch,
options?: {
exact?: boolean = true,
@@ -420,21 +413,20 @@ Will also find a `title` element within an SVG.
```js
-import { getByTitle } from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
-const container = document.body
-const deleteElement = getByTitle(container, 'Delete')
-const closeElement = getByTitle(container, 'Close')
+const deleteElement = screen.getByTitle('Delete')
+const closeElement = screen.getByTitle('Close')
```
```js
-import { render } from '@testing-library/react'
+import { render, screen } from '@testing-library/react'
-const { getByTitle } = render( )
-const deleteElement = getByTitle('Delete')
-const closeElement = getByTitle('Close')
+render( )
+const deleteElement = screen.getByTitle('Delete')
+const closeElement = screen.getByTitle('Close')
```
@@ -453,7 +445,7 @@ cy.getByTitle('Close').should('exist')
```typescript
getByDisplayValue(
- container: HTMLElement,
+ container: HTMLElement, // if you're using `screen`, then skip this argument
value: TextMatch,
options?: {
exact?: boolean = true,
@@ -479,19 +471,18 @@ document.getElementById('lastName').value = 'Norris'
```js
-import { getByDisplayValue } from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
-const container = document.body
-const lastNameInput = getByDisplayValue(container, 'Norris')
+const lastNameInput = screen.getByDisplayValue('Norris')
```
```js
-import { render } from '@testing-library/react'
+import { render, screen } from '@testing-library/react'
-const { getByDisplayValue } = render( )
-const lastNameInput = getByDisplayValue('Norris')
+render( )
+const lastNameInput = screen.getByDisplayValue('Norris')
```
@@ -517,19 +508,18 @@ document.getElementById('messageTextArea').value = 'Hello World'
```js
-import { getByDisplayValue } from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
-const container = document.body
-const messageTextArea = getByDisplayValue(container, 'Hello World')
+const messageTextArea = screen.getByDisplayValue('Hello World')
```
```js
-import { render } from '@testing-library/react'
+import { render, screen } from '@testing-library/react'
-const { getByDisplayValue } = render( )
-const messageTextArea = getByDisplayValue('Hello World')
+render( )
+const messageTextArea = screen.getByDisplayValue('Hello World')
```
@@ -559,19 +549,18 @@ matches the given [`TextMatch`](#textmatch).
```js
-import { getByDisplayValue } from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
-const container = document.body
-const selectElement = getByDisplayValue(container, 'Alaska')
+const selectElement = screen.getByDisplayValue('Alaska')
```
```js
-import { render } from '@testing-library/react'
+import { render, screen } from '@testing-library/react'
-const { getByDisplayValue } = render( )
-const selectElement = getByDisplayValue('Alaska')
+render( )
+const selectElement = screen.getByDisplayValue('Alaska')
```
@@ -589,7 +578,7 @@ cy.getByDisplayValue('Alaska').should('exist')
```typescript
getByRole(
- container: HTMLElement,
+ container: HTMLElement, // if you're using `screen`, then skip this argument
role: TextMatch,
options?: {
exact?: boolean = true,
@@ -659,19 +648,18 @@ The default value can [be configured](api-configuration#configuration).
```js
-import { getByRole } from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
-const container = document.body
-const dialogContainer = getByRole(container, 'dialog')
+const dialogContainer = screen.getByRole('dialog')
```
```js
-import { render } from '@testing-library/react'
+import { render, screen } from '@testing-library/react'
-const { getByRole } = render( )
-const dialogContainer = getByRole('dialog')
+render( )
+const dialogContainer = screen.getByRole('dialog')
```
@@ -689,7 +677,7 @@ cy.getByRole('dialog').should('exist')
```typescript
getByTestId(
- container: HTMLElement,
+ container: HTMLElement, // if you're using `screen`, then skip this argument
text: TextMatch,
options?: {
exact?: boolean = true,
@@ -709,19 +697,18 @@ also accepts a [`TextMatch`](#textmatch)).
```js
-import { getByTestId } from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
-const container = document.body
-const element = getByTestId(container, 'custom-element')
+const element = screen.getByTestId('custom-element')
```
```js
-import { render } from '@testing-library/react'
+import { render, screen } from '@testing-library/react'
-const { getByTestId } = render( )
-const element = getByTestId('custom-element')
+render( )
+const element = screen.getByTestId('custom-element')
```
@@ -797,7 +784,7 @@ behaviour:
To perform a match against text without trimming:
```javascript
-getByText(node, 'text', {
+screen.getByText('text', {
normalizer: getDefaultNormalizer({ trim: false }),
})
```
@@ -806,7 +793,7 @@ To override normalization to remove some Unicode characters whilst keeping some
(but not all) of the built-in normalization behavior:
```javascript
-getByText(node, 'text', {
+screen.getByText('text', {
normalizer: str =>
getDefaultNormalizer({ trim: false })(str).replace(/[\u200E-\u200F]*/g, ''),
})
@@ -824,31 +811,31 @@ Given the following HTML:
```javascript
// Matching a string:
-getByText(container, 'Hello World') // full string match
-getByText(container, 'llo Worl', { exact: false }) // substring match
-getByText(container, 'hello world', { exact: false }) // ignore case
+screen.getByText('Hello World') // full string match
+screen.getByText('llo Worl', { exact: false }) // substring match
+screen.getByText('hello world', { exact: false }) // ignore case
// Matching a regex:
-getByText(container, /World/) // substring match
-getByText(container, /world/i) // substring match, ignore case
-getByText(container, /^hello world$/i) // full string match, ignore case
-getByText(container, /Hello W?oRlD/i) // advanced regex
+screen.getByText(/World/) // substring match
+screen.getByText(/world/i) // substring match, ignore case
+screen.getByText(/^hello world$/i) // full string match, ignore case
+screen.getByText(/Hello W?oRlD/i) // advanced regex
// Matching with a custom function:
-getByText(container, (content, element) => content.startsWith('Hello'))
+screen.getByText((content, element) => content.startsWith('Hello'))
```
**_Will not_ find the div:**
```javascript
// full string does not match
-getByText(container, 'Goodbye World')
+screen.getByText('Goodbye World')
// case-sensitive regex with different case
-getByText(container, /hello world/)
+screen.getByText(/hello world/)
// function looking for a span when it's actually a div:
-getByText(container, (content, element) => {
+screen.getByText((content, element) => {
return element.tagName.toLowerCase() === 'span' && content.startsWith('Hello')
})
```
From 64c167849217ca4cb22ab7bc2b71010d201e493b Mon Sep 17 00:00:00 2001
From: karthik20
Date: Thu, 9 Apr 2020 12:52:27 +0800
Subject: [PATCH 095/903] Documentation correction for new async utility
waitFor (#436)
Updating the example description as the previous example given for `waitFor` doesn't match the old description.
---
docs/dom-testing-library/api-async.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-async.md b/docs/dom-testing-library/api-async.md
index 5272e04ad..7c7fe39b0 100644
--- a/docs/dom-testing-library/api-async.md
+++ b/docs/dom-testing-library/api-async.md
@@ -29,7 +29,7 @@ expectations to pass. Here's a simple example:
```javascript
// ...
// Wait until the callback does not throw an error. In this case, that means
-// it'll wait until we can get a form control with a label that matches "username".
+// it'll wait until the mock function has been called once.
await waitFor(() => expect(mockAPI).toHaveBeenCalledTimes(1))
// ...
```
From edc519e128c86880c76d1cf0ff30fc81d14ebb53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20Dugu=C3=A9?=
Date: Thu, 9 Apr 2020 19:37:20 +0200
Subject: [PATCH 096/903] fixed a minor typo (#435)
that can still cause a lot of confusion :)
---
docs/react-testing-library/setup.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/react-testing-library/setup.md b/docs/react-testing-library/setup.md
index a142df8b0..493257c81 100644
--- a/docs/react-testing-library/setup.md
+++ b/docs/react-testing-library/setup.md
@@ -214,7 +214,7 @@ _Typescript config needs to be updated as follow:_
// ...,
+ "baseUrl": "src",
+ "paths": {
-+ "test-utils": ["../utils/test-utils"]
++ "test-utils": ["./utils/test-utils"]
+ }
}
}
From 6312fd86be4972e470ae04f0912beda1d9728825 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Thu, 9 Apr 2020 11:37:49 -0600
Subject: [PATCH 097/903] docs: add mdugue as a contributor (#437)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 3 +++
2 files changed, 12 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 4961f8ec1..ce59c9e5d 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -639,6 +639,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "mdugue",
+ "name": "Manuel DuguΓ©",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/894149?v=4",
+ "profile": "http://manueldugue.de/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index cff558253..4c69654d4 100644
--- a/README.md
+++ b/README.md
@@ -124,6 +124,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Matan Borenkraout π
timrobinson33 π
+
+ Manuel DuguΓ© π
+
From b8d9ef53bcf768044203662daa15dce752063823 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Thu, 9 Apr 2020 22:35:03 -0600
Subject: [PATCH 098/903] docs: add karthik20 as a contributor (#438)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index ce59c9e5d..dd01441e2 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -648,6 +648,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "karthik20",
+ "name": "karthik20",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/12153250?v=4",
+ "profile": "https://github.com/karthik20",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 4c69654d4..fd35bc428 100644
--- a/README.md
+++ b/README.md
@@ -126,6 +126,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Manuel DuguΓ© π
+ karthik20 π
From f6593b871ce2c690208001d0f449faeb7f8c697e Mon Sep 17 00:00:00 2001
From: Pob Ch <590650@gmail.com>
Date: Sun, 12 Apr 2020 21:31:11 +0700
Subject: [PATCH 099/903] Typo in api-events.md (#440)
---
docs/dom-testing-library/api-events.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-events.md b/docs/dom-testing-library/api-events.md
index e626f1d95..9ccb901bf 100644
--- a/docs/dom-testing-library/api-events.md
+++ b/docs/dom-testing-library/api-events.md
@@ -66,7 +66,7 @@ element in the DOM and the key you want to fire.
```javascript
fireEvent.keyDown(domNode, { key: 'Enter', code: 'Enter' })
-fireEvent.keyDown(domNode, { key: 'A', code: 'KeyQ' })
+fireEvent.keyDown(domNode, { key: 'A', code: 'KeyA' })
```
You can find out which key code to use at
From a5652b7ed735b78a3a2e6ffffc0120cab2cfd3d6 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 12 Apr 2020 08:31:47 -0600
Subject: [PATCH 100/903] docs: add pobch as a contributor (#441)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index dd01441e2..167055bed 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -657,6 +657,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "pobch",
+ "name": "Pob Ch",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/19894957?v=4",
+ "profile": "https://github.com/pobch",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index fd35bc428..4a4d53688 100644
--- a/README.md
+++ b/README.md
@@ -127,6 +127,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Manuel DuguΓ© π
karthik20 π
+ Pob Ch π
From e4c9389bf865d42e0631a0e2f9329eaa574dbfab Mon Sep 17 00:00:00 2001
From: Mohammad Kermani
Date: Wed, 15 Apr 2020 15:59:06 +0430
Subject: [PATCH 101/903] Update api-queries.md (#442)
---
docs/dom-testing-library/api-queries.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index 7db41f461..dbd00e469 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -38,9 +38,9 @@ more than one element is found after a default timeout of `1000`ms. If you need
to find more than one element, then use `findAllBy`.
> 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.
-> `screen.findByText('text', queryOptions, waitForElementOptions)`)
+> [`waitFor`](/docs/api-async#waitfor). The `findBy*` queries
+> accept the `waitFor` options as the last argument. (i.e.
+> `screen.findByText('text', queryOptions, waitForOptions)`)
### findAllBy
From 124cd52448dd100e1ce7664a2feea29038151a67 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Wed, 15 Apr 2020 05:29:35 -0600
Subject: [PATCH 102/903] docs: add mkermani144 as a contributor (#443)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 167055bed..e8ea9a5b3 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -666,6 +666,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "mkermani144",
+ "name": "Mohammad Kermani",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/12621708?v=4",
+ "profile": "https://github.com/mkermani144",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 4a4d53688..50f1f370d 100644
--- a/README.md
+++ b/README.md
@@ -128,6 +128,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Manuel DuguΓ© π
karthik20 π
Pob Ch π
+ Mohammad Kermani π
From 846f50e348abb964515450137248a0a3cf362b62 Mon Sep 17 00:00:00 2001
From: Adeel Imran
Date: Thu, 16 Apr 2020 00:39:43 +0200
Subject: [PATCH 103/903] add await to example (#444)
---
docs/ecosystem-user-event.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/ecosystem-user-event.md b/docs/ecosystem-user-event.md
index 3686b8d6b..444d21494 100644
--- a/docs/ecosystem-user-event.md
+++ b/docs/ecosystem-user-event.md
@@ -19,7 +19,7 @@ import userEvent from '@testing-library/user-event'
test('click', () => {
const { getByRole } = render()
- userEvent.type(getByRole('textbox'), 'Hello, World!')
+ await userEvent.type(getByRole('textbox'), 'Hello, World!')
expect(getByRole('textbox')).toHaveAttribute('value', 'Hello, World!')
})
```
From 2241434d0590336021de2ac1de63783675bbb731 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Wed, 15 Apr 2020 16:40:12 -0600
Subject: [PATCH 104/903] docs: add adeelibr as a contributor (#445)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index e8ea9a5b3..800be7742 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -675,6 +675,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "adeelibr",
+ "name": "Adeel Imran",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/16651811?v=4",
+ "profile": "http://twitter.com/adeelibr",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 50f1f370d..d55dc3897 100644
--- a/README.md
+++ b/README.md
@@ -129,6 +129,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
karthik20 π
Pob Ch π
Mohammad Kermani π
+ Adeel Imran π
From 8ec761f7fb01640f1d63fdb9481e431c302b5a59 Mon Sep 17 00:00:00 2001
From: mayas
Date: Thu, 16 Apr 2020 16:35:49 +0200
Subject: [PATCH 105/903] docs: update events link in cheatsheets
---
docs/dom-testing-library/cheatsheet.md | 2 +-
docs/react-testing-library/cheatsheet.md | 2 +-
docs/vue-testing-library/cheatsheet.md | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/dom-testing-library/cheatsheet.md b/docs/dom-testing-library/cheatsheet.md
index 72b3391ea..c5070482a 100644
--- a/docs/dom-testing-library/cheatsheet.md
+++ b/docs/dom-testing-library/cheatsheet.md
@@ -98,7 +98,7 @@ See [Considerations for fireEvent](guide-events.md), [Events API](api-events.md)
- **fireEvent** trigger DOM event: `fireEvent(node, event)`
- **fireEvent.\*** helpers for default event types
- **click** `fireEvent.click(node)`
- - [See all supported events](https://github.com/testing-library/dom-testing-library/blob/master/src/events.js)
+ - [See all supported events](https://github.com/testing-library/dom-testing-library/blob/master/src/event-map.js)
## Other
diff --git a/docs/react-testing-library/cheatsheet.md b/docs/react-testing-library/cheatsheet.md
index a59a99135..5dd3c883f 100644
--- a/docs/react-testing-library/cheatsheet.md
+++ b/docs/react-testing-library/cheatsheet.md
@@ -127,7 +127,7 @@ See [Events API](dom-testing-library/api-events.md)
- **fireEvent** trigger DOM event: `fireEvent(node, event)`
- **fireEvent.\*** helpers for default event types
- **click** `fireEvent.click(node)`
- - [See all supported events](https://github.com/testing-library/dom-testing-library/blob/master/src/events.js)
+ - [See all supported events](https://github.com/testing-library/dom-testing-library/blob/master/src/event-map.js)
- **act** wrapper around
[react-dom/test-utils act](https://reactjs.org/docs/test-utils.html#act);
React Testing Library wraps render and fireEvent in a call to `act` already so
diff --git a/docs/vue-testing-library/cheatsheet.md b/docs/vue-testing-library/cheatsheet.md
index b697d0d94..ef7a9a3c2 100644
--- a/docs/vue-testing-library/cheatsheet.md
+++ b/docs/vue-testing-library/cheatsheet.md
@@ -71,7 +71,7 @@ For more information, see
- **fireEvent.\*** helpers for default event types
- **click** `fireEvent.click(node)`
- **input** `fireEvent.input(node, event)`
- - [See all supported events](https://github.com/testing-library/dom-testing-library/blob/master/src/events.js)
+ - [See all supported events](https://github.com/testing-library/dom-testing-library/blob/master/src/event-map.js)
For more information, see [Events API](dom-testing-library/api-events.md)
From a847da2ab1e3c381feda4ad9aa284be58f79f046 Mon Sep 17 00:00:00 2001
From: Varun Dey
Date: Fri, 17 Apr 2020 02:20:29 +0530
Subject: [PATCH 106/903] Update wrapper link (#447)
---
docs/react-testing-library/setup.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/react-testing-library/setup.md b/docs/react-testing-library/setup.md
index 493257c81..6202c95f0 100644
--- a/docs/react-testing-library/setup.md
+++ b/docs/react-testing-library/setup.md
@@ -26,7 +26,7 @@ all your imports. See [below](#configuring-jest-with-test-utils) for a way to
make your test util file accessible without using relative paths.
The example below sets up data providers using the
-[`wrapper`](api.md#render-options) option to `render`.
+[`wrapper`](api.md#wrapper) option to `render`.
```diff
// my-component.test.js
From e9dfe2c99fe4a646044ee652f0d7937d8a3aa605 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Thu, 16 Apr 2020 14:51:07 -0600
Subject: [PATCH 107/903] docs: add varundey as a contributor (#448)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 800be7742..8d5949bce 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -684,6 +684,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "varundey",
+ "name": "Varun Dey",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/9202135?v=4",
+ "profile": "https://varundey.me/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index d55dc3897..11cca24f6 100644
--- a/README.md
+++ b/README.md
@@ -130,6 +130,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Pob Ch π
Mohammad Kermani π
Adeel Imran π
+ Varun Dey π
From 9be370f583e29ce17bc28f4c0d47c4fa6a9cac3a Mon Sep 17 00:00:00 2001
From: Mike Dane
Date: Wed, 29 Apr 2020 08:09:22 +1000
Subject: [PATCH 108/903] fixed example code typo (#449)
---
docs/react-testing-library/example-intro.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/react-testing-library/example-intro.md b/docs/react-testing-library/example-intro.md
index b5554346b..fe800acd9 100644
--- a/docs/react-testing-library/example-intro.md
+++ b/docs/react-testing-library/example-intro.md
@@ -87,7 +87,7 @@ axiosMock.get.mockResolvedValueOnce({
data: { greeting: 'hello there' },
})
-fireEvent.click(getByText('Load Greeting'))
+fireEvent.click(screen.getByText('Load Greeting'))
// Wait until the mocked `get` request promise resolves and
// the component calls setState and re-renders.
From 28acc7f7b5c28d58f25e3fe5cec5a60a4d130e0b Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Wed, 29 Apr 2020 12:35:42 -0600
Subject: [PATCH 109/903] use screen
---
docs/guide-disappearance.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/guide-disappearance.md b/docs/guide-disappearance.md
index 05be8acd7..6ccf1194f 100644
--- a/docs/guide-disappearance.md
+++ b/docs/guide-disappearance.md
@@ -65,7 +65,7 @@ if you want to make an assertion that an element is _not_ present in the DOM,
you can use `queryBy` APIs instead:
```javascript
-const submitButton = queryByText(container, 'submit')
+const submitButton = screen.queryByText('submit')
expect(submitButton).toBeNull() // it doesn't exist
```
@@ -74,7 +74,7 @@ array can be useful for assertions after elements are added or removed from the
DOM.
```javascript
-const submitButtons = queryAllByText(container, 'submit')
+const submitButtons = screen.queryAllByText('submit')
expect(submitButtons).toHaveLength(2) // expect 2 elements
```
@@ -88,7 +88,7 @@ a query result is `null`.
```javascript
import '@testing-library/jest-dom/extend-expect'
// use `queryBy` to avoid throwing an error with `getBy`
-const submitButton = queryByText(container, 'submit')
+const submitButton = screen.queryByText('submit')
expect(submitButton).not.toBeInTheDocument()
```
From 59689cd7569708e0d9c21de86bebe76fdb3be7f9 Mon Sep 17 00:00:00 2001
From: Wesley Ellis
Date: Wed, 29 Apr 2020 18:13:35 -0400
Subject: [PATCH 110/903] fix typo in svelte-testing-library/api
Replace `binded` with `bound`
---
docs/svelte-testing-library/api.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/svelte-testing-library/api.md b/docs/svelte-testing-library/api.md
index 43f87d87c..03741ac94 100644
--- a/docs/svelte-testing-library/api.md
+++ b/docs/svelte-testing-library/api.md
@@ -71,7 +71,7 @@ const { results } = render(YourComponent, { myProp: 'value' })
| `debug` | Logs the `container` using [prettyDom](https://testing-library.com/docs/dom-testing-library/api-helpers#prettydom). |
| `unmount` | Unmounts the component from the `target` by calling `component.$destroy()`. |
| `rerender` | Calls render again destroying the old component, and mounting the new component on the original `target` with any new options passed in. |
-| `...queries` | Returns all [query functions](https://testing-library.com/docs/dom-testing-library/api-queries) that are binded to the `container`. If you pass in `query` arguments than this will be those, otherwise all. |
+| `...queries` | Returns all [query functions](https://testing-library.com/docs/dom-testing-library/api-queries) that are bound to the `container`. If you pass in `query` arguments than this will be those, otherwise all. |
## `cleanup`
From b6f741b3b7d841144d034c473f07352258559257 Mon Sep 17 00:00:00 2001
From: cheshireoctopus
Date: Thu, 30 Apr 2020 13:21:27 -0400
Subject: [PATCH 111/903] Adds comma to testcafe example code
---
docs/testcafe-testing-library/intro.md | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/docs/testcafe-testing-library/intro.md b/docs/testcafe-testing-library/intro.md
index f5a39e5fb..69d3aad15 100644
--- a/docs/testcafe-testing-library/intro.md
+++ b/docs/testcafe-testing-library/intro.md
@@ -5,13 +5,17 @@ title: Testcafe Testing Library
## Introduction
-[`testcafe-testing-library`][gh] allows the use of dom testing library queries within
-[Testcafe](https://devexpress.github.io/testcafe/) for cross-browser end-to-end web
-testing.
+[`testcafe-testing-library`][gh] allows the use of dom testing library queries
+within [Testcafe](https://devexpress.github.io/testcafe/) for cross-browser
+end-to-end web testing.
-If you are new to the testing-library approach for writing tests, check out the [this guide on which query to use](https://testing-library.com/docs/guide-which-query) as well as the [cheat sheet](https://testing-library.com/docs/dom-testing-library/cheatsheet).
+If you are new to the testing-library approach for writing tests, check out the
+[this guide on which query to use](https://testing-library.com/docs/guide-which-query)
+as well as the
+[cheat sheet](https://testing-library.com/docs/dom-testing-library/cheatsheet).
## Install
+
```
npm install --save-dev testcafe @testing-library/testcafe
```
@@ -35,7 +39,12 @@ You can now import & use get[All]By*, query[All]By*, find[All]By\* selectors in
your tests.
[See `DOM Testing Library` API for reference](dom-testing-library/api-queries.md)
-> A note about queries in testcafe. Testcafe has [built in waiting](https://devexpress.github.io/testcafe/documentation/test-api/built-in-waiting-mechanisms.html#wait-mechanism-for-selectors), for this reason, there's no difference between `queryBy` and `findBy` queries in testcafe testing library. `getBy` queries will throw an exception (as designed) so they will fail immediately and do not work with the built in waiting that Testcafe provides.
+> A note about queries in testcafe. Testcafe has
+> [built in waiting](https://devexpress.github.io/testcafe/documentation/test-api/built-in-waiting-mechanisms.html#wait-mechanism-for-selectors),
+> for this reason, there's no difference between `queryBy` and `findBy` queries
+> in testcafe testing library. `getBy` queries will throw an exception (as
+> designed) so they will fail immediately and do not work with the built in
+> waiting that Testcafe provides.
## Examples
@@ -43,7 +52,6 @@ To show some simple examples (from
[https://github.com/testing-library/testcafe-testing-library/blob/master/tests/testcafe/selectors.js](https://github.com/testing-library/testcafe-testing-library/blob/master/tests/testcafe/selectors.js)):
```javascript
-
test('getByPlaceHolderText', async t => {
await t.typeText(
getByPlaceholderText('Placeholder Text'),
@@ -116,7 +124,7 @@ test('still works after browser page load and reload', async t => {
```json
"clientScripts": [
- "./node_modules/@testing-library/dom/dist/@testing-library/dom.umd.js"
+ "./node_modules/@testing-library/dom/dist/@testing-library/dom.umd.js",
"./path/to/my-app-testcafe.config.js"
]
```
@@ -131,8 +139,8 @@ window.TestingLibraryDom.configure({ testIdAttribute: 'data-automation-id' })
By default the selectors come pre-bound to `document.body`, so no need to
provide a container. However, if you want to restrict your query using a
-container, you can use `within` which can take either a
-string or a query (get[All]By*, query[All]By*, find[All]By\*).
+container, you can use `within` which can take either a string or a query
+(get[All]By*, query[All]By*, find[All]By\*).
### Examples using `within`
From 81c4558371d1c9c86e2e3759d2eb9ae9d9e2dc5b Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Mon, 4 May 2020 09:31:52 -0600
Subject: [PATCH 112/903] Update api.md
---
docs/react-testing-library/api.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/docs/react-testing-library/api.md b/docs/react-testing-library/api.md
index 936e67e60..7bbb50932 100644
--- a/docs/react-testing-library/api.md
+++ b/docs/react-testing-library/api.md
@@ -160,6 +160,10 @@ renders its HTML directly in the body.
### `debug`
+> NOTE: It's recommended to use
+> [`screen.debug`](https://testing-library.com/docs/dom-testing-library/api-queries#screendebug)
+> instead.
+
This method is a shortcut for `console.log(prettyDOM(baseElement))`.
```jsx
From ddb20d93d2eea0da3cd6260f8a809114d2b3c2e3 Mon Sep 17 00:00:00 2001
From: "Pablo R. Dinella"
Date: Mon, 4 May 2020 15:03:28 -0300
Subject: [PATCH 113/903] Add leaning material link in portuguese (#453)
---
docs/learning.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/docs/learning.md b/docs/learning.md
index d9622189a..206744a79 100644
--- a/docs/learning.md
+++ b/docs/learning.md
@@ -38,4 +38,8 @@ sidebar_label: Learning Material
by [Gpx](https://twitter.com/Gpx)
- [Writing better tests with react-testing-library](https://www.youtube.com/watch?v=O0VxvRqgm7g) by [Billy Mathews](https://twitter.com/BillRMathews)
+## Portuguese π§π·
+
+- [Do Enzyme ao Testing Library](https://www.infoq.com/br/presentations/enzyme-para-react-testing-library/) by [Pablo Dinella](https://github.com/PabloDinella)
+
Feel free to contribute more!
From 6a26a8e94e07914775547a593473055d05500827 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Mon, 4 May 2020 12:03:49 -0600
Subject: [PATCH 114/903] docs: add PabloDinella as a contributor (#455)
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 8d5949bce..25be369c9 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -693,6 +693,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "PabloDinella",
+ "name": "Pablo R. Dinella",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/2482730?v=4",
+ "profile": "http://pablodinella.com/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 11cca24f6..dcbdbec14 100644
--- a/README.md
+++ b/README.md
@@ -131,6 +131,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Mohammad Kermani π
Adeel Imran π
Varun Dey π
+ Pablo R. Dinella π
From c47f1e68b8feb74945d6d3eca190d84562c81ba2 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Mon, 4 May 2020 12:05:37 -0600
Subject: [PATCH 115/903] Update guide-which-query.md (#454)
---
docs/guide-which-query.md | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/docs/guide-which-query.md b/docs/guide-which-query.md
index 30312a604..bbb822c1e 100644
--- a/docs/guide-which-query.md
+++ b/docs/guide-which-query.md
@@ -11,20 +11,23 @@ possible. With this in mind, we recommend this order of priority:
1. **Queries Accessible to Everyone** queries that reflect the experience of
visual/mouse users as well as those that use assistive technology
+ 1. `getByRole`: This can be used to query every element that is exposed in
+ the
+ [accessibility tree](https://developer.mozilla.org/en-US/docs/Glossary/AOM).
+ With the `name` option you can filter the returned elements by their
+ [accessible name](https://www.w3.org/TR/accname-1.1/). This should be your
+ top preference for just about everything. There's not much you can't get
+ with this (if you can't, it's possible your UI is inaccessible). Most
+ often, this will be used with the `name` option like so:
+ `getByRole('button', {name: /submit/i})`
1. `getByLabelText`: Only really good for form fields, but this is the number
one method a user finds those elements, so it should be your top
preference.
1. `getByPlaceholderText`:
[A placeholder is not a substitute for a label](https://www.nngroup.com/articles/form-design-placeholders/).
But if that's all you have, then it's better than alternatives.
- 1. `getByRole`: This can be used to query every element that is exposed in
- the
- [accessibility tree](https://developer.mozilla.org/en-US/docs/Glossary/AOM).
- With the `name` option you can filter the returned elements by their
- [accessible name](https://www.w3.org/TR/accname-1.1/). This should be your
- top preference for interactive elements such as buttons.
1. `getByText`: Not useful for forms, but this is the number 1 method a user
- finds most non-interactive elements (listitems or divs).
+ finds most non-interactive elements (like divs and spans).
1. `getByDisplayValue`: The current value of a form element can be useful
when navigating a page with filled-in values.
1. **Semantic Queries** HTML5 and ARIA compliant selectors. Note that the user
From 59f72cf53556634de5b31f58e83fa29e5cd71977 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Mon, 4 May 2020 12:37:28 -0600
Subject: [PATCH 116/903] Update learning.md
---
docs/learning.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/docs/learning.md b/docs/learning.md
index 206744a79..7c55687cc 100644
--- a/docs/learning.md
+++ b/docs/learning.md
@@ -8,6 +8,9 @@ sidebar_label: Learning Material
about testing JavaScript applications (See also the
[course material with many examples using React Testing Library](https://github.com/kentcdodds/react-testing-library-course))
by [Kent C. Dodds](https://github.com/kentcdodds)
+- [Kent C. Dodds's testing related blog post are all relevant](https://kentcdodds.com/blog?q=test)
+ (especially
+ [Common mistakes with React Testing Library](https://kentcdodds.com/blog/common-mistakes-with-react-testing-library))
- [Migrating from Enzyme shallow rendering to explicit component mocks](https://www.youtube.com/watch?v=LHUdxkThTM0&list=PLV5CVI1eNcJgCrPH_e6d57KRUTiDZgs0u)
- [Confident React](https://www.youtube.com/watch?v=qXRPHRgcXJ0&list=PLV5CVI1eNcJgNqzNwcs4UKrlJdhfDjshf)
- [Test Driven Development with React Testing Library](https://www.youtube.com/watch?v=kCR3JAR7CHE&list=PLV5CVI1eNcJgCrPH_e6d57KRUTiDZgs0u)
From 1907b78857af40e649f65987a3abd4322fe8683d Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Mon, 4 May 2020 12:40:57 -0600
Subject: [PATCH 117/903] Update learning.md
---
docs/learning.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/learning.md b/docs/learning.md
index 7c55687cc..e128891f9 100644
--- a/docs/learning.md
+++ b/docs/learning.md
@@ -8,7 +8,7 @@ sidebar_label: Learning Material
about testing JavaScript applications (See also the
[course material with many examples using React Testing Library](https://github.com/kentcdodds/react-testing-library-course))
by [Kent C. Dodds](https://github.com/kentcdodds)
-- [Kent C. Dodds's testing related blog post are all relevant](https://kentcdodds.com/blog?q=test)
+- [Kent C. Dodds's testing related blog posts are all relevant](https://kentcdodds.com/blog?q=test)
(especially
[Common mistakes with React Testing Library](https://kentcdodds.com/blog/common-mistakes-with-react-testing-library))
- [Migrating from Enzyme shallow rendering to explicit component mocks](https://www.youtube.com/watch?v=LHUdxkThTM0&list=PLV5CVI1eNcJgCrPH_e6d57KRUTiDZgs0u)
From ea15db89abea14f4710ea6c7484884592a1b37a8 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Tue, 5 May 2020 11:28:23 -0600
Subject: [PATCH 118/903] add config option (#457)
---
docs/dom-testing-library/api-configuration.md | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/docs/dom-testing-library/api-configuration.md b/docs/dom-testing-library/api-configuration.md
index 9bd93e47e..2abd43ead 100644
--- a/docs/dom-testing-library/api-configuration.md
+++ b/docs/dom-testing-library/api-configuration.md
@@ -18,6 +18,13 @@ Configuration options:
`defaultHidden`: The default value for the `hidden` option used by
[`getByRole`](api-queries#byrole). Defaults to `false`.
+`showOriginalStackTrace`: By default, `waitFor` will ensure that the stack trace
+for errors thrown by Testing Library is cleaned up and shortened so it's easier
+for you to identify the part of your code that resulted in the error (async
+stack traces are hard to debug). If you want to disable this, then set
+`showOriginalStackTrace` to `false`. You can also disable this for a specific
+call in the options you pass to `waitFor`.
+
`testIdAttribute`: The attribute used by [`getByTestId`](api-queries#bytestid)
and related queries. Defaults to `data-testid`.
From 61034fef080669558e07386aa86e0b98dc0e00bd Mon Sep 17 00:00:00 2001
From: Sebastian Silbermann
Date: Wed, 6 May 2020 22:55:58 +0200
Subject: [PATCH 119/903] docs(ByRole): Add { selected: boolean } option (#458)
---
docs/dom-testing-library/api-queries.md | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index dbd00e469..fc0bb08f8 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -585,6 +585,7 @@ getByRole(
hidden?: boolean = true,
name?: TextMatch,
normalizer?: NormalizerFn,
+ selected?: boolean,
}): HTMLElement
```
@@ -637,7 +638,27 @@ case. For example in
assertions about the `Open dialog`-button you would need to use
`getAllByRole('button', { hidden: true })`.
-The default value can [be configured](api-configuration#configuration).
+The default value for `hidden` can [be configured](api-configuration#configuration).
+
+Certain roles can have a selected state. You can filter the
+returned elements that by their selected state
+by setting `selected: true` or `selected: false`.
+
+For example in
+
+```html
+
+
+ Native
+ React
+ Cypress
+
+
+```
+
+you can get the "Native"-tab by calling `getByRole('tab', { selected: true })`.
+To learn more about the selected state and which elements can
+have this state see [ARIA `aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected).
```html
...
From 7bedb53d3736f0394f79c72399aef79db7f84b60 Mon Sep 17 00:00:00 2001
From: Jamie
Date: Fri, 8 May 2020 02:41:56 +0900
Subject: [PATCH 120/903] docs: add dataTransfer event property info (#459)
---
docs/dom-testing-library/api-events.md | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/docs/dom-testing-library/api-events.md b/docs/dom-testing-library/api-events.md
index 9ccb901bf..2e6f972d6 100644
--- a/docs/dom-testing-library/api-events.md
+++ b/docs/dom-testing-library/api-events.md
@@ -59,6 +59,21 @@ fireEvent.change(getByLabelText(/picture/i), {
})
```
+**dataTransfer**: Drag events have a `dataTransfer` property that contains
+data transferred during the operation. As a convenience, if you provide a
+`dataTransfer` property in the `eventProperties` (second argument), then
+those properties will be added to the event.
+
+This should predominantly be used for testing drag and drop interactions.
+
+```javascript
+fireEvent.drop(getByLabelText(/drop files here/i), {
+ dataTransfer: {
+ files: [new File(['(ββ‘_β‘)'], 'chucknorris.png', { type: 'image/png' })],
+ },
+})
+```
+
**Keyboard events**: There are three event types related to keyboard input -
`keyPress`, `keyDown`, and `keyUp`. When firing these you need to reference an
element in the DOM and the key you want to fire.
From f509f5e8cb8dac36d421c39e109e2f12741d08fe Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Thu, 7 May 2020 11:42:18 -0600
Subject: [PATCH 121/903] docs: add jamsinclair as a contributor (#460)
---
.all-contributorsrc | 9 +++++++++
README.md | 3 +++
2 files changed, 12 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 25be369c9..566a313f4 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -702,6 +702,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "jamsinclair",
+ "name": "Jamie",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/5964236?v=4",
+ "profile": "https://jamie.tokyo/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index dcbdbec14..b2532b5f3 100644
--- a/README.md
+++ b/README.md
@@ -133,6 +133,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Varun Dey π
Pablo R. Dinella π
+
+ Jamie π
+
From 4c01fba834a3acef40de785b584a9df5a739a2b5 Mon Sep 17 00:00:00 2001
From: Cory House
Date: Sun, 10 May 2020 23:42:27 -0500
Subject: [PATCH 122/903] Update cy examples to use find* (#462)
---
docs/dom-testing-library/api-queries.md | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index fc0bb08f8..c91e50790 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -245,7 +245,7 @@ const inputNode = screen.getByPlaceholderText('Username')
```js
-cy.getByPlaceholderText('Username').should('exist')
+cy.findByPlaceholderText('Username').should('exist')
```
@@ -301,7 +301,7 @@ const aboutAnchorNode = screen.getByText(/about/i)
```js
-cy.getByText(/about/i).should('exist')
+cy.findByText(/about/i).should('exist')
```
@@ -376,7 +376,7 @@ const incrediblesPosterImg = screen.getByAltText(/incredibles.*? poster/i)
```js
-cy.getByAltText(/incredibles.*? poster/i).should('exist')
+cy.findByAltText(/incredibles.*? poster/i).should('exist')
```
@@ -432,8 +432,8 @@ const closeElement = screen.getByTitle('Close')
```js
-cy.getByTitle('Delete').should('exist')
-cy.getByTitle('Close').should('exist')
+cy.findByTitle('Delete').should('exist')
+cy.findByTitle('Close').should('exist')
```
@@ -488,7 +488,7 @@ const lastNameInput = screen.getByDisplayValue('Norris')
```js
-cy.getByDisplayValue('Norris').should('exist')
+cy.findByDisplayValue('Norris').should('exist')
```
@@ -525,7 +525,7 @@ const messageTextArea = screen.getByDisplayValue('Hello World')
```js
-cy.getByDisplayValue('Hello World').should('exist')
+cy.findByDisplayValue('Hello World').should('exist')
```
@@ -566,7 +566,7 @@ const selectElement = screen.getByDisplayValue('Alaska')
```js
-cy.getByDisplayValue('Alaska').should('exist')
+cy.findByDisplayValue('Alaska').should('exist')
```
@@ -641,7 +641,7 @@ assertions about the `Open dialog`-button you would need to use
The default value for `hidden` can [be configured](api-configuration#configuration).
Certain roles can have a selected state. You can filter the
-returned elements that by their selected state
+returned elements by their selected state
by setting `selected: true` or `selected: false`.
For example in
@@ -686,7 +686,7 @@ const dialogContainer = screen.getByRole('dialog')
```js
-cy.getByRole('dialog').should('exist')
+cy.findByRole('dialog').should('exist')
```
@@ -735,7 +735,7 @@ const element = screen.getByTestId('custom-element')
```js
-cy.getByTestId('custom-element').should('exist')
+cy.findByTestId('custom-element').should('exist')
```
From 8a78164a3c433b271d62f6dda1090559e8d902fb Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 10 May 2020 22:43:06 -0600
Subject: [PATCH 123/903] docs: add coryhouse as a contributor (#463)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 566a313f4..a5f6eb289 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -711,6 +711,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "coryhouse",
+ "name": "Cory House",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/1688997?v=4",
+ "profile": "http://www.bitnative.com/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index b2532b5f3..96aa54b6a 100644
--- a/README.md
+++ b/README.md
@@ -135,6 +135,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Jamie π
+ Cory House π
From 20e09e0c56e8e62e0c8fa671d9b1edf7d30a9855 Mon Sep 17 00:00:00 2001
From: Jack Zhao
Date: Mon, 11 May 2020 02:55:40 -0700
Subject: [PATCH 124/903] docs(api-queries): Fix getByAltText function name
(#461)
---
docs/dom-testing-library/api-queries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index c91e50790..8d8e9035c 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -612,7 +612,7 @@ accessible name query does not replace other queries such as `*ByAlt` or
`*ByTitle`. While the accessible name can be equal to these attributes, it does
not replace the functionality of these attributes. For example
` ` will be returned for both
-`getByAlt('fancy image')` and `getByRole('image', { name: 'fancy image' })`.
+`getByAltText('fancy image')` and `getByRole('image', { name: 'fancy image' })`.
However, the image will not display its description if `fancy.jpg` could not be
loaded. Whether you want assert this functionality in your test or not is up to
you.
From fea63c4d21ed6974997fc7dba3ba949088ea1cf8 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Mon, 11 May 2020 12:02:52 +0200
Subject: [PATCH 125/903] docs: add bugzpodder as a contributor (#464)
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index a5f6eb289..e110b9d92 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -720,6 +720,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "bugzpodder",
+ "name": "Jack Zhao",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/14841421?v=4",
+ "profile": "http://fb.me/yz",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 96aa54b6a..795d6a26c 100644
--- a/README.md
+++ b/README.md
@@ -136,6 +136,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Jamie π
Cory House π
+ Jack Zhao π
From a473c97ead8412a3a7808d2c1508ae96b49807c5 Mon Sep 17 00:00:00 2001
From: Cory House
Date: Mon, 11 May 2020 08:19:59 -0500
Subject: [PATCH 126/903] Switch to cy.findByText (#465)
---
docs/dom-testing-library/api-helpers.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-helpers.md b/docs/dom-testing-library/api-helpers.md
index 7b7d45f1b..c9a18c661 100644
--- a/docs/dom-testing-library/api-helpers.md
+++ b/docs/dom-testing-library/api-helpers.md
@@ -150,7 +150,7 @@ within(signinModal).getByPlaceholderText('Username')
```js
cy.get('form').within(() => {
- cy.getByText('Button Text').should('be.disabled')
+ cy.findByText('Button Text').should('be.disabled')
})
```
From 21f82098c92b1ce2a0c77529cad52b0409e06a17 Mon Sep 17 00:00:00 2001
From: Daniel K
Date: Fri, 15 May 2020 16:20:00 +0200
Subject: [PATCH 127/903] Add link to known aria roles (#466)
---
docs/guide-which-query.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/guide-which-query.md b/docs/guide-which-query.md
index bbb822c1e..7dd7aa8ee 100644
--- a/docs/guide-which-query.md
+++ b/docs/guide-which-query.md
@@ -19,7 +19,7 @@ possible. With this in mind, we recommend this order of priority:
top preference for just about everything. There's not much you can't get
with this (if you can't, it's possible your UI is inaccessible). Most
often, this will be used with the `name` option like so:
- `getByRole('button', {name: /submit/i})`
+ `getByRole('button', {name: /submit/i})`. Check the [list of roles](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#Roles).
1. `getByLabelText`: Only really good for form fields, but this is the number
one method a user finds those elements, so it should be your top
preference.
From 4438476a508c4583255af73de34290bd141a10fa Mon Sep 17 00:00:00 2001
From: Qingyu Deng
Date: Sun, 17 May 2020 23:43:40 +0800
Subject: [PATCH 128/903] fix: fix broken stub example link in VTL docs
---
docs/vue-testing-library/faq.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/vue-testing-library/faq.md b/docs/vue-testing-library/faq.md
index 5d0fcfd5e..8621521ab 100644
--- a/docs/vue-testing-library/faq.md
+++ b/docs/vue-testing-library/faq.md
@@ -90,6 +90,6 @@ Links:
[vue-test-utils]: https://github.com/vuejs/vue-test-utils
[mount]: https://vue-test-utils.vuejs.org/api/#mount
[stubs]: https://vue-test-utils.vuejs.org/api/options.html#stubs
-[stubs-example]: https://github.com/testing-library/vue-testing-library/blob/master/tests/__tests__/stubs.js
+[stubs-example]: https://github.com/testing-library/vue-testing-library/blob/master/src/__tests__/stubs.js
From f6283d2a70b3a9836a08f3e8003cae05c7a7a98f Mon Sep 17 00:00:00 2001
From: Christopher Dambamuromo
Date: Mon, 18 May 2020 10:08:39 +0100
Subject: [PATCH 129/903] fix: add async to test method
Add async to test method since it uses await on `userEvent.type(...)`
---
docs/ecosystem-user-event.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/ecosystem-user-event.md b/docs/ecosystem-user-event.md
index 444d21494..5444f37b3 100644
--- a/docs/ecosystem-user-event.md
+++ b/docs/ecosystem-user-event.md
@@ -16,7 +16,7 @@ import React from 'react'
import { render } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
-test('click', () => {
+test('click', async () => {
const { getByRole } = render()
await userEvent.type(getByRole('textbox'), 'Hello, World!')
From df5f8f0a92333aac1fb2b1d82e514ebd04db2045 Mon Sep 17 00:00:00 2001
From: Stephan Meijer
Date: Fri, 22 May 2020 20:30:59 +0200
Subject: [PATCH 130/903] add links to testing-playground.com (#471)
---
docs/example-codesandbox.md | 5 +++++
docs/example-external.md | 5 +++++
docs/guide-which-query.md | 10 +++++++++-
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/docs/example-codesandbox.md b/docs/example-codesandbox.md
index e028f2099..d1f292887 100644
--- a/docs/example-codesandbox.md
+++ b/docs/example-codesandbox.md
@@ -9,3 +9,8 @@ You can find runnable examples for many common use cases on Codesandbox.
[](https://codesandbox.io/s/github/kentcdodds/react-testing-library-examples/tree/master/)
+
+## Playground
+
+Are you looking for a quick way to run queries against your own html instead?
+Try [testing-playground.com](https://testing-playground.com)
diff --git a/docs/example-external.md b/docs/example-external.md
index fa4b369d8..560019d39 100644
--- a/docs/example-external.md
+++ b/docs/example-external.md
@@ -9,6 +9,11 @@ sidebar_label: External Examples
- You can find more React Testing Library examples at
[react-testing-examples.com](https://react-testing-examples.com/jest-rtl/).
+## Playground
+
+- An interactive sandbox with visual feedback on different queries
+ [testing-playground.com](https://testing-playground.com).
+
## Videos
- [What is React Testing Library?](https://youtu.be/JKOwJUM4_RM) by Scott
diff --git a/docs/guide-which-query.md b/docs/guide-which-query.md
index 7dd7aa8ee..9d0631139 100644
--- a/docs/guide-which-query.md
+++ b/docs/guide-which-query.md
@@ -19,7 +19,8 @@ possible. With this in mind, we recommend this order of priority:
top preference for just about everything. There's not much you can't get
with this (if you can't, it's possible your UI is inaccessible). Most
often, this will be used with the `name` option like so:
- `getByRole('button', {name: /submit/i})`. Check the [list of roles](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#Roles).
+ `getByRole('button', {name: /submit/i})`. Check the
+ [list of roles](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#Roles).
1. `getByLabelText`: Only really good for form fields, but this is the number
one method a user finds those elements, so it should be your top
preference.
@@ -55,3 +56,10 @@ testid if you have to.
const { container } = render( )
const foo = container.querySelector('[data-foo="bar"]')
```
+
+## Playground
+
+If you want to get more familiar with these queries, you can try them out on
+[testing-playground.com](https://testing-playground.com). Testing Playground is
+an interactive sandbox where you can run different queries against your own
+html, and get visual feedback matching the rules mentioned above.
From 0e4e102373def2cf34114bbe57c4c132aa013262 Mon Sep 17 00:00:00 2001
From: Ryan Kennel
Date: Sun, 24 May 2020 22:44:01 -0400
Subject: [PATCH 131/903] Add example of firing select event (#472)
---
docs/react-testing-library/faq.md | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/docs/react-testing-library/faq.md b/docs/react-testing-library/faq.md
index 939c4e4d2..cc9429ef1 100644
--- a/docs/react-testing-library/faq.md
+++ b/docs/react-testing-library/faq.md
@@ -28,6 +28,20 @@ test('change values via the fireEvent.change method', () => {
expect(input.value).toBe('a')
})
+test('select drop-downs must use the fireEvent.change', () => {
+ const handleChange = jest.fn()
+ const { container } = render(1 2 )
+ const select = container.firstChild;
+ const option1 = container.getElementsByTagName("option").item(0);
+ const option2 = container.getElementsByTagName("option").item(1);
+
+ fireEvent.change(select, {target: {value: "2"}});
+
+ expect(handleChange).toHaveBeenCalledTimes(1);
+ expect(option1.selected).toBe(false);
+ expect(option2.selected).toBe(true);
+})
+
test('checkboxes (and radios) must use fireEvent.click', () => {
const handleChange = jest.fn()
const { container } = render(
From 6469d477a0b6e2ef0ab3124e306f4d299d962941 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 24 May 2020 20:44:51 -0600
Subject: [PATCH 132/903] docs: add rkennel as a contributor (#473)
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index e110b9d92..e599cc1f6 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -729,6 +729,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "rkennel",
+ "name": "Ryan Kennel",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/28492538?v=4",
+ "profile": "https://github.com/rkennel",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 795d6a26c..d6777afca 100644
--- a/README.md
+++ b/README.md
@@ -137,6 +137,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Jamie π
Cory House π
Jack Zhao π
+ Ryan Kennel π
From 844badf8498a116456c86f69bc46a46a6ad34ce1 Mon Sep 17 00:00:00 2001
From: Jesus Hernandez
Date: Mon, 25 May 2020 09:07:59 -0500
Subject: [PATCH 133/903] docs(api-queries): Adds comma to the subtitle in the
ByLabelText section (#474)
---
docs/dom-testing-library/api-queries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index 8d8e9035c..52934a8c6 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -115,7 +115,7 @@ screen.debug(screen.getAllByText('multi-test'))
### `ByLabelText`
-> getByLabelText, queryByLabelText, getAllByLabelText, queryAllByLabelText
+> getByLabelText, queryByLabelText, getAllByLabelText, queryAllByLabelText,
> findByLabelText, findAllByLabelText
```typescript
From cce765eda10f0e8250ec38b0d2bbfc7ba10d18c8 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Mon, 25 May 2020 08:08:23 -0600
Subject: [PATCH 134/903] docs: add JesuHrz as a contributor (#475)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index e599cc1f6..868af8f83 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -738,6 +738,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "JesuHrz",
+ "name": "Jesus Hernandez",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/28031187?v=4",
+ "profile": "https://github.com/JesuHrz",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index d6777afca..ec5ff25b8 100644
--- a/README.md
+++ b/README.md
@@ -138,6 +138,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Cory House π
Jack Zhao π
Ryan Kennel π
+ Jesus Hernandez π
From 6633463db46dd537b2b159f8f20e8a6b1d77a234 Mon Sep 17 00:00:00 2001
From: Pierre Grimaud
Date: Mon, 25 May 2020 17:20:33 +0200
Subject: [PATCH 135/903] Fix typos
---
docs/example-react-intl.md | 2 +-
docs/vue-testing-library/api.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/example-react-intl.md b/docs/example-react-intl.md
index 1fa954bd0..9ae7fa6ed 100644
--- a/docs/example-react-intl.md
+++ b/docs/example-react-intl.md
@@ -74,7 +74,7 @@ const renderWithReactIntl = component => {
setupTests()
-test('it should render FormattedDate and have a formated pt date', () => {
+test('it should render FormattedDate and have a formatted pt date', () => {
const { container } = renderWithReactIntl( )
expect(getByTestId(container, 'date-display')).toHaveTextContent('11/03/2019')
})
diff --git a/docs/vue-testing-library/api.md b/docs/vue-testing-library/api.md
index b8ca10aa6..eebfc6ab3 100644
--- a/docs/vue-testing-library/api.md
+++ b/docs/vue-testing-library/api.md
@@ -213,7 +213,7 @@ await fireEvent.blur(getByLabelText('username'))
### `update(elem, value)`
Properly handles inputs controlled by `v-model`. It updates the
-input/select/textarea inner value while emitting the appropiate native event.
+input/select/textarea inner value while emitting the appropriate native event.
See a working example of `update` in the
[v-model example test](/docs/vue-testing-library/examples#example-using-v-model).
From a8c684a37f99132cf55c282c0892da809e8cc46c Mon Sep 17 00:00:00 2001
From: Quentin Dreyer
Date: Fri, 29 May 2020 10:54:59 +0200
Subject: [PATCH 136/903] docs: fix default hidden option value for getByRole
query (#478)
https://github.com/testing-library/testing-library-docs/blob/ea15db89abea14f4710ea6c7484884592a1b37a8/docs/dom-testing-library/api-configuration.md#L18
---
docs/dom-testing-library/api-queries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index 52934a8c6..e055a683a 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -582,7 +582,7 @@ getByRole(
role: TextMatch,
options?: {
exact?: boolean = true,
- hidden?: boolean = true,
+ hidden?: boolean = false,
name?: TextMatch,
normalizer?: NormalizerFn,
selected?: boolean,
From 732aad318529190a6f73ed0abfe039614a53c5fe Mon Sep 17 00:00:00 2001
From: Cory House
Date: Fri, 29 May 2020 09:53:50 -0500
Subject: [PATCH 137/903] docs: update intro.md (#479)
Co-authored-by: Kent C. Dodds
---
docs/cypress-testing-library/intro.md | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/docs/cypress-testing-library/intro.md b/docs/cypress-testing-library/intro.md
index 2bc1d1228..9c4c2e90f 100644
--- a/docs/cypress-testing-library/intro.md
+++ b/docs/cypress-testing-library/intro.md
@@ -52,15 +52,15 @@ To show some simple examples (from
[cypress/integration/query.spec.js](https://github.com/testing-library/cypress-testing-library/blob/master/cypress/integration/query.spec.js) or [cypress/integration/find.spec.js](https://github.com/testing-library/cypress-testing-library/blob/master/cypress/integration/find.spec.js)):
```javascript
-cy.findAllByText('Jackie Chan').click()
-cy.findByText('Button Text').should('exist')
-cy.findByText('Non-existing Button Text').should('not.exist')
-cy.findByLabelText('Label text', {timeout: 7000}).should('exist')
+cy.findByRole('button', {name: /Jackie Chan/i}).click()
+cy.findByRole('button', {name: /Button Text/i}).should('exist')
+cy.findByRole('button', {name: /Non-existing Button Text/i}).should('not.exist')
+cy.findByLabelText(/Label text/i, {timeout: 7000}).should('exist')
// findAllByText _inside_ a form element
-cy.get('form').findByText('Button Text').should('exist')
-cy.get('form').then(subject => {
- cy.findByText('Button Text', {container: subject}).should('exist')
+cy.get('form').findByText('button', {name: /Button Text/i}).should('exist')
+cy.findByRole('dialog').within(() => {
+ cy.findByRole('button', {name: /confirm/i})
})
```
From 9319ccc08786588e984d1dce7b737172807173b0 Mon Sep 17 00:00:00 2001
From: Ben Monro
Date: Fri, 29 May 2020 11:47:41 -0700
Subject: [PATCH 138/903] docs: added showSuggestions (#477)
* docs: added showSuggestions
* Update api-configuration.md
* Update api-configuration.md
* Update api-configuration.md
* Update docs/dom-testing-library/api-configuration.md
Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
Co-authored-by: Kent C. Dodds
Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
---
docs/dom-testing-library/api-configuration.md | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/docs/dom-testing-library/api-configuration.md b/docs/dom-testing-library/api-configuration.md
index 2abd43ead..2c82abd33 100644
--- a/docs/dom-testing-library/api-configuration.md
+++ b/docs/dom-testing-library/api-configuration.md
@@ -24,6 +24,13 @@ for you to identify the part of your code that resulted in the error (async
stack traces are hard to debug). If you want to disable this, then set
`showOriginalStackTrace` to `false`. You can also disable this for a specific
call in the options you pass to `waitFor`.
+`throwSuggestions`: (experimental) When enabled, if [better queries](https://testing-library.com/docs/guide-which-query) are available
+the test will fail and provide a suggested query to use instead. Default to `false`.
+
+To disable a suggestion for a single query just add `{suggest:false}` as an option.
+```js
+screen.getByTestId("foo", {suggest:false}); // will not throw a suggestion
+```
`testIdAttribute`: The attribute used by [`getByTestId`](api-queries#bytestid)
and related queries. Defaults to `data-testid`.
From fc2c2ea2474637dc335bd822e24be969848dc5c3 Mon Sep 17 00:00:00 2001
From: Ben Monro
Date: Fri, 29 May 2020 14:18:54 -0700
Subject: [PATCH 139/903] fixed newline issue on config page (#481)
---
docs/dom-testing-library/api-configuration.md | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/docs/dom-testing-library/api-configuration.md b/docs/dom-testing-library/api-configuration.md
index 2c82abd33..dfb00cbac 100644
--- a/docs/dom-testing-library/api-configuration.md
+++ b/docs/dom-testing-library/api-configuration.md
@@ -21,9 +21,9 @@ Configuration options:
`showOriginalStackTrace`: By default, `waitFor` will ensure that the stack trace
for errors thrown by Testing Library is cleaned up and shortened so it's easier
for you to identify the part of your code that resulted in the error (async
-stack traces are hard to debug). If you want to disable this, then set
-`showOriginalStackTrace` to `false`. You can also disable this for a specific
+stack traces are hard to debug). If you want to disable this, then set`showOriginalStackTrace` to `false`. You can also disable this for a specific
call in the options you pass to `waitFor`.
+
`throwSuggestions`: (experimental) When enabled, if [better queries](https://testing-library.com/docs/guide-which-query) are available
the test will fail and provide a suggested query to use instead. Default to `false`.
@@ -32,6 +32,7 @@ To disable a suggestion for a single query just add `{suggest:false}` as an opti
screen.getByTestId("foo", {suggest:false}); // will not throw a suggestion
```
+
`testIdAttribute`: The attribute used by [`getByTestId`](api-queries#bytestid)
and related queries. Defaults to `data-testid`.
From 2570111cd9af6660fba113084eae8194f7abb313 Mon Sep 17 00:00:00 2001
From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
Date: Wed, 3 Jun 2020 07:56:02 +0200
Subject: [PATCH 140/903] docs(angular): update to latest version (#450)
---
docs/angular-testing-library/api.md | 70 ++++++++++++++++--------
docs/angular-testing-library/examples.md | 12 ++--
2 files changed, 54 insertions(+), 28 deletions(-)
diff --git a/docs/angular-testing-library/api.md b/docs/angular-testing-library/api.md
index dc67fdb31..3f65ad3f6 100644
--- a/docs/angular-testing-library/api.md
+++ b/docs/angular-testing-library/api.md
@@ -9,6 +9,16 @@ well as these methods:
- [`render`](<(#render)>)
+Some of the `DOM Testing Library` re-exports are patched to work easier with
+Angular:
+
+- The events on `fireEvent` automatically invoke a change detection cycle after
+ the event has been fired
+- The `findBy` queries automatically invoke a change detection cycle before the
+ query is invoked function
+- The `waitFor` functions automatically invoke a change detection cycle before
+ invoking the callback function
+
## `render`
```typescript
@@ -189,6 +199,20 @@ const component = await render(AppComponent, {
})
```
+### `removeAngularAttributes`
+
+Removes the Angular attributes (ng-version, and root-id) from the fixture.
+
+**default** : `false`
+
+**example**:
+
+```typescript
+const component = await render(AppComponent, {
+ removeAngularAttributes: true,
+})
+```
+
## Directive RenderOptions
To test a directive, the render API is a bit different. The API has the same
@@ -244,11 +268,11 @@ component.debug(component.getByRole('alert'))
### `rerender`
-Re-render the same component with different props.
-Will call `detectChanges` after props has been updated.
+Re-render the same component with different props. Will call `detectChanges`
+after props has been updated.
```typescript
-const component = await render(Counter, { componentProperties: { count: 4 }})
+const component = await render(Counter, { componentProperties: { count: 4 } })
expect(component.getByTestId('count-value').textContent).toBe('4')
@@ -258,11 +282,11 @@ expect(component.getByTestId('count-value').textContent).toBe('7')
### `fireEvent.***`
-The second most important feature of `render` is that the events from
-[DOM Testing Library](https://testing-library.com/docs/dom-testing-library) are
-automatically bound to the Angular Component. This to ensure that the Angular
-change detection has been run by calling `detectChanges` after an event has been
-fired.
+The `fireEvents` re-exported from
+[DOM Testing Library](https://testing-library.com/docs/dom-testing-library) that
+are automatically bound to the Angular Component. This to ensure that the
+Angular change detection has been run by invoking `detectChanges` after an event
+has been fired.
See
[Firing Events](https://testing-library.com/docs/dom-testing-library/api-events)
@@ -281,6 +305,12 @@ component.change(component.getByLabelText('Username'), {
component.click(component.getByText('Login'))
```
+### `debugElement`
+
+The Angular `DebugElement` of the component.
+
+For more info see the [Angular docs](https://angular.io/api/core/DebugElement).
+
### `fixture`
The Angular `ComponentFixture` of the component.
@@ -355,23 +385,19 @@ component.type(component.getByLabelText('Username'), 'Tim')
component.type(component.getByLabelText('Username'), 'Tim', { delay: 250 })
```
-### `waitForDomChange`
-
-Wait for the DOM to change.
-For more info see the [DOM Testing Library docs](https://testing-library.com/docs/dom-testing-library/api-async#waitfordomchange).
-
-This function will also call `detectChanges` repeatably to update the DOM, is helpful to test async functionality.
-
-### `waitForElement`
+### `waitFor`
-Wait for DOM elements to appear, disappear, or change.
-For more info see the [DOM Testing Library docs](https://testing-library.com/docs/dom-testing-library/api-async#waitforelement).
+When in need to wait for any period of time you can use waitFor, to wait for
+your expectations to pass. For more info see the
+[DOM Testing Library docs](https://testing-library.com/docs/dom-testing-library/api-async#waitFor).
-This function will also call `detectChanges` repeatably to update the DOM, is helpful to test async functionality.
+This function will also call `detectChanges` repeatably to update the DOM, which
+is helpful to test async functionalities.
### `waitForElementToBeRemoved`
-Wait for the removal of element(s) from the DOM.
-For more info see the [DOM Testing Library docs](https://testing-library.com/docs/dom-testing-library/api-async#waitforelementtoberemoved).
+Wait for the removal of element(s) from the DOM. For more info see the
+[DOM Testing Library docs](https://testing-library.com/docs/dom-testing-library/api-async#waitforelementtoberemoved).
-This function will also call `detectChanges` repeatably to update the DOM, is helpful to test async functionality.
+This function will also call `detectChanges` repeatably to update the DOM, which
+is helpful to test async functionalities.
diff --git a/docs/angular-testing-library/examples.md b/docs/angular-testing-library/examples.md
index 966d09fc0..232ad4797 100644
--- a/docs/angular-testing-library/examples.md
+++ b/docs/angular-testing-library/examples.md
@@ -35,26 +35,26 @@ export class CounterComponent {
counter.component.spec.ts
```typescript
-import { render } from '@testing-library/angular'
+import { render, screen, fireEvent } from '@testing-library/angular'
import { CounterComponent } from './counter.component.ts'
describe('Counter', () => {
test('should render counter', async () => {
- const { getByText } = await render(CounterComponent, {
+ await render(CounterComponent, {
componentProperties: { counter: 5 },
})
- expect(getByText('Current Count: 5'))
+ expect(screen.getByText('Current Count: 5'))
})
test('should increment the counter on click', async () => {
- const { getByText, click } = await render(CounterComponent, {
+ await render(CounterComponent, {
componentProperties: { counter: 5 },
})
- click(getByText('+'))
+ fireEvent.click(screen.getByText('+'))
- expect(getByText('Current Count: 6'))
+ expect(screen.getByText('Current Count: 6'))
})
})
```
From 3861509b68a4ee383461753dee2c60a5fe51e39e Mon Sep 17 00:00:00 2001
From: Artem Zakharchenko
Date: Thu, 4 Jun 2020 16:02:39 +0200
Subject: [PATCH 141/903] docs: replace "axiosMock" with "msw" in React Testing
Library example (#483)
---
docs/react-testing-library/example-intro.md | 166 +++++++++++++-------
1 file changed, 110 insertions(+), 56 deletions(-)
diff --git a/docs/react-testing-library/example-intro.md b/docs/react-testing-library/example-intro.md
index fe800acd9..a7753cbde 100644
--- a/docs/react-testing-library/example-intro.md
+++ b/docs/react-testing-library/example-intro.md
@@ -11,32 +11,55 @@ See the following sections for a detailed breakdown of the test
```jsx
// __tests__/fetch.test.js
import React from 'react'
+import { rest } from 'msw'
+import { setupServer } from 'msw/node'
import { render, fireEvent, waitFor, screen } from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'
-import axiosMock from 'axios'
import Fetch from '../fetch'
-jest.mock('axios')
+const server = setupServer(
+ rest.get('/greeting', (req, res, ctx) => {
+ return res(ctx.json({ greeting: 'hello there' }))
+ })
+)
-test('loads and displays greeting', async () => {
- const url = '/greeting'
- render( )
+beforeAll(() => server.listen())
+afterEach(() => server.resetHandlers())
+afterAll(() => server.close())
- axiosMock.get.mockResolvedValueOnce({
- data: { greeting: 'hello there' },
- })
+test('loads and displays greeting', async () => {
+ render( )
fireEvent.click(screen.getByText('Load Greeting'))
await waitFor(() => screen.getByRole('heading'))
- expect(axiosMock.get).toHaveBeenCalledTimes(1)
- expect(axiosMock.get).toHaveBeenCalledWith(url)
expect(screen.getByRole('heading')).toHaveTextContent('hello there')
expect(screen.getByRole('button')).toHaveAttribute('disabled')
})
+
+test('handlers server error', async () => {
+ server.use(
+ rest.get('/greeting', (req, res, ctx) => {
+ return res(ctx.status(500))
+ })
+ )
+
+ render( )
+
+ fireEvent.click(screen.getByText('Load Greeting'))
+
+ await waitFor(() => screen.getByRole('alert'))
+
+ expect(screen.getByRole('alert')).toHaveTextContent('Oops, failed to fetch!')
+ expect(screen.getByRole('button')).not.toHaveAttribute('disabled')
+})
```
+> We recommend using [Mock Service Worker](https://github.com/mswjs/msw) library
+> to declaratively mock API communication in your tests instead of stubbing
+> `window.fetch`, or relying on third-party adapters.
+
---
## Step-By-Step
@@ -47,17 +70,17 @@ test('loads and displays greeting', async () => {
// import dependencies
import React from 'react'
+// import API mocking utilities from Mock Service Worker
+import { rest } from 'msw'
+import { setupServer } from 'msw/node'
+
// import react-testing methods
import { render, fireEvent, waitFor, screen } from '@testing-library/react'
// add custom jest matchers from jest-dom
import '@testing-library/jest-dom/extend-expect'
-import axiosMock from 'axios'
// the component to test
import Fetch from '../fetch'
-
-// https://jestjs.io/docs/en/mock-functions#mocking-modules
-jest.mock('axios')
```
```jsx
@@ -68,13 +91,51 @@ test('loads and displays greeting', async () => {
})
```
+### Mock
+
+Use the `setupServer` function from `msw` to mock an API request that our tested
+component makes.
+
+```js
+// declare which API requests to mock
+const server = setupServer(
+ // capture "GET /greeting" requests
+ rest.get('/greeting', (req, res, ctx) => {
+ // respond using a mocked JSON body
+ return res(ctx.json({ greeting: 'hello there' }))
+ })
+)
+
+// establish API mocking before all tests
+beforeAll(() => server.listen())
+// reset any request handlers that are declared as a part of our tests
+// (i.e. for testing one-time error scenarios)
+afterEach(() => server.resetHandlers())
+// clean up once the tests are done
+afterAll(() => server.close())
+
+// ...
+
+test('handlers server error', async () => {
+ server.use(
+ // override the initial "GET /greeting" request handler
+ // to return a 500 Server Error
+ rest.get('/greeting', (req, res, ctx) => {
+ return res(ctx.status(500))
+ })
+ )
+
+ // ...
+})
+```
+
### Arrange
-The [`render`](./api#render) method renders a React element into the DOM and returns utility functions for testing the component.
+The [`render`](./api#render) method renders a React element into the DOM and
+returns utility functions for testing the component.
```jsx
-const url = '/greeting'
-const { container, asFragment } = render( )
+const { container, asFragment } = render( )
```
### Act
@@ -83,13 +144,9 @@ The [`fireEvent`](dom-testing-library/api-events.md) method allows you to fire
events to simulate user actions.
```jsx
-axiosMock.get.mockResolvedValueOnce({
- data: { greeting: 'hello there' },
-})
-
fireEvent.click(screen.getByText('Load Greeting'))
-// Wait until the mocked `get` request promise resolves and
+// wait until the `get` request promise resolves and
// the component calls setState and re-renders.
// `waitFor` waits until the callback doesn't throw an error
@@ -107,16 +164,39 @@ fetch.js
import React, { useState } from 'react'
import axios from 'axios'
+function greetingReducer(state, action) {
+ switch (action.type) {
+ case 'SUCCESS': {
+ return {
+ error: null,
+ greeting: action.greeting,
+ }
+ }
+ case: 'ERROR': {
+ error: action.error,
+ greeting: null
+ }
+ default: {
+ return state
+ }
+ }
+}
+
export default function Fetch({ url }) {
- const [greeting, setGreeting] = useState('')
+ const [{ error, greeting }, dispatch] = useReducer(greetingReducer)
const [buttonClicked, setButtonClicked] = useState(false)
const fetchGreeting = async () => {
- const response = await axios.get(url)
- const data = response.data
- const { greeting } = data
- setGreeting(greeting)
- setButtonClicked(true)
+ axios.get(url)
+ .then((response) => {
+ const { data } = response
+ const { greeting } = data
+ dispatch({ type: 'SUCCESS', greeting })
+ setButtonClicked(true)
+ })
+ .catch((error) => {
+ dispatch({ type: 'ERROR' })
+ })
}
const buttonText = buttonClicked ? 'Ok' : 'Load Greeting'
@@ -126,35 +206,9 @@ export default function Fetch({ url }) {
{buttonText}
- {greeting ? {greeting} : null}
+ {greeting && {greeting} }
+ {error && Oops, failed to fetch!
}
)
}
```
-
-```jsx
-expect(axiosMock.get).toHaveBeenCalledTimes(1)
-expect(axiosMock.get).toHaveBeenCalledWith(url)
-expect(screen.getByRole('heading')).toHaveTextContent('hello there')
-expect(screen.getByRole('button')).toHaveAttribute('disabled')
-
-// snapshots work great with regular DOM nodes!
-expect(container).toMatchInlineSnapshot(`
-
-
-
- Ok
-
-
- hello there
-
-
-
-`)
-
-// you can also use get a `DocumentFragment`,
-// which is useful if you want to compare nodes across render
-expect(asFragment()).toMatchSnapshot()
-```
From 663eb61f31c62f0f87963c057529ad38ed7ae2a3 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 7 Jun 2020 15:11:44 +0000
Subject: [PATCH 142/903] docs: update README.md [skip ci]
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index ec5ff25b8..d70923506 100644
--- a/README.md
+++ b/README.md
@@ -139,6 +139,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Jack Zhao π
Ryan Kennel π
Jesus Hernandez π
+ Aaron Pettengill π
From d66c1814e8a745f49b7c391a7272c4479d322cbe Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 7 Jun 2020 15:11:45 +0000
Subject: [PATCH 143/903] docs: update .all-contributorsrc [skip ci]
---
.all-contributorsrc | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 868af8f83..e9a6f0666 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -747,6 +747,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "airjp73",
+ "name": "Aaron Pettengill",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/25882770?v=4",
+ "profile": "https://github.com/airjp73",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
From db958d607694f7e3891b249ca374aeec6f867a83 Mon Sep 17 00:00:00 2001
From: ilias bhallil
Date: Mon, 8 Jun 2020 15:06:03 -0400
Subject: [PATCH 144/903] fix typo in example-intro.md
---
docs/react-testing-library/example-intro.md | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/docs/react-testing-library/example-intro.md b/docs/react-testing-library/example-intro.md
index a7753cbde..7ef8514f5 100644
--- a/docs/react-testing-library/example-intro.md
+++ b/docs/react-testing-library/example-intro.md
@@ -173,8 +173,10 @@ function greetingReducer(state, action) {
}
}
case: 'ERROR': {
- error: action.error,
- greeting: null
+ return {
+ error: action.error,
+ greeting: null
+ }
}
default: {
return state
From 7a3b6abcafc5deec9b98f9347e37f086f4ccb52a Mon Sep 17 00:00:00 2001
From: Ben Monro
Date: Tue, 9 Jun 2020 06:07:50 -0700
Subject: [PATCH 145/903] update testcafe docs for `screen.` (#494)
---
docs/testcafe-testing-library/intro.md | 35 +++++++++++++++-----------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/docs/testcafe-testing-library/intro.md b/docs/testcafe-testing-library/intro.md
index 69d3aad15..3752c0d32 100644
--- a/docs/testcafe-testing-library/intro.md
+++ b/docs/testcafe-testing-library/intro.md
@@ -35,8 +35,11 @@ Add the following to your .testcaferc.json file:
],
```
-You can now import & use get[All]By*, query[All]By*, find[All]By\* selectors in
+You can now import `screen` which has all the get[All]By*, query[All]By*, find[All]By\* selectors that you can use in
your tests.
+
+`import { screen } from '@testing-library/testcafe'`
+
[See `DOM Testing Library` API for reference](dom-testing-library/api-queries.md)
> A note about queries in testcafe. Testcafe has
@@ -52,26 +55,28 @@ To show some simple examples (from
[https://github.com/testing-library/testcafe-testing-library/blob/master/tests/testcafe/selectors.js](https://github.com/testing-library/testcafe-testing-library/blob/master/tests/testcafe/selectors.js)):
```javascript
+import { screen } from '@testing-library/testcafe'
+
test('getByPlaceHolderText', async t => {
await t.typeText(
- getByPlaceholderText('Placeholder Text'),
+ screen.getByPlaceholderText('Placeholder Text'),
'Hello Placeholder'
)
})
test('getByText', async t => {
- await t.click(getByText('getByText'))
+ await t.click(screen.getByText('getByText'))
})
test('getByLabelText', async t => {
await t.typeText(
- getByLabelText('Label For Input Labelled By Id'),
+ screen.getByLabelText('Label For Input Labelled By Id'),
'Hello Input Labelled By Id'
)
})
test('queryAllByText', async t => {
- await t.expect(queryAllByText('Button Text').exists).ok()
- await t.expect(queryAllByText('Non-existing Button Text').exists).notOk()
+ await t.expect(screen.queryAllByText('Button Text').exists).ok()
+ await t.expect(screen.queryAllByText('Non-existing Button Text').exists).notOk()
})
```
@@ -87,31 +92,31 @@ import { configureOnce, getByTestId } from '@testing-library/testcafe'
test('can be configured once in a single page load', async t => {
await configureOnce({ testIdAttribute: 'data-other-test-id' })
- await t.click(getByTestId('other-id'))
+ await t.click(screen.getByTestId('other-id'))
})
```
### For every test & page load in a fixture:
```javascript
-import { configure, getByTestId, getByText } from '@testing-library/testcafe'
+import { configure, screen } from '@testing-library/testcafe'
fixture`configure`.clientScripts(
configure({ testIdAttribute: 'data-automation-id' })
).page`http://localhost:13370`
test('supports alternative testIdAttribute', async t => {
- await t.click(getByTestId('image-with-random-alt-tag'))
+ await t.click(screen.getByTestId('image-with-random-alt-tag'))
})
test('still works after browser page load and reload', async t => {
- await t.click(getByText('Go to Page 2'))
+ await t.click(screen.getByText('Go to Page 2'))
await t.eval(() => location.reload(true))
await t
- .click(getByTestId('page2-thing'))
- .expect(getByText('second page').exists)
+ .click(screen.getByTestId('page2-thing'))
+ .expect(screen.getByText('second page').exists)
.ok()
})
```
@@ -145,13 +150,13 @@ container, you can use `within` which can take either a string or a query
### Examples using `within`
```javascript
-import { within } from '@testing-library/testcafe'
+import { within, screen } from '@testing-library/testcafe'
fixture`within`.page`http://localhost:13370`
test('works with getBy* selectors', async t => {
await t
- .expect(within(getByTestId('nested')).getByText('Button Text').exists)
+ .expect(within(screen.getByTestId('nested')).getByText('Button Text').exists)
.ok()
})
@@ -167,7 +172,7 @@ test('works on any testcafe selector', async t => {
})
test('works with results from "byAll" query with index - regex', async t => {
- const nestedDivs = getAllByTestId(/nested/)
+ const nestedDivs = screen.getAllByTestId(/nested/)
await t.expect(nestedDivs.count).eql(2)
await t
From c20fb031a02a416961a6c204ca3ae63433a6e899 Mon Sep 17 00:00:00 2001
From: Izhaki
Date: Fri, 12 Jun 2020 04:31:14 +0100
Subject: [PATCH 146/903] docs: Add drag example to recipes (#497)
Related: #495
---
docs/example-drag.md | 101 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
create mode 100644 docs/example-drag.md
diff --git a/docs/example-drag.md b/docs/example-drag.md
new file mode 100644
index 000000000..afa11154d
--- /dev/null
+++ b/docs/example-drag.md
@@ -0,0 +1,101 @@
+---
+id: example-drag
+title: Drag
+sidebar_label: Drag
+---
+
+> **Note**
+>
+> This example only works with a real browser (not with jsdom, as it does not support `getBoundingClientRect`).
+
+# Usage
+
+```js
+await drag(slider, {
+ delta: { x: -100, y: 0 },
+});
+```
+
+# Kapture
+
+
+
+# Code
+
+```js
+import { fireEvent } from '@testing-library/dom';
+
+// https://stackoverflow.com/a/53946549/1179377
+function isElement(obj) {
+ if (typeof obj !== 'object') {
+ return false;
+ }
+ let prototypeStr, prototype;
+ do {
+ prototype = Object.getPrototypeOf(obj);
+ // to work in iframe
+ prototypeStr = Object.prototype.toString.call(prototype);
+ // '[object Document]' is used to detect document
+ if (
+ prototypeStr === '[object Element]' ||
+ prototypeStr === '[object Document]'
+ ) {
+ return true;
+ }
+ obj = prototype;
+ // null is the terminal of object
+ } while (prototype !== null);
+ return false;
+}
+
+function getElementClientCenter(element) {
+ const { left, top, width, height } = element.getBoundingClientRect();
+ return {
+ x: left + width / 2,
+ y: top + height / 2,
+ };
+}
+
+const getCoords = (charlie) =>
+ isElement(charlie) ? getElementClientCenter(charlie) : charlie;
+
+const sleep = (ms) =>
+ new Promise((resolve) => {
+ setTimeout(resolve, ms);
+ });
+
+export default async function drag(
+ element,
+ { to: inTo, delta, steps = 20, duration = 500 }
+) {
+ const from = getElementClientCenter(element);
+ const to = delta
+ ? {
+ x: from.x + delta.x,
+ y: from.y + delta.y,
+ }
+ : getCoords(inTo);
+
+ const step = {
+ x: (to.x - from.x) / steps,
+ y: (to.y - from.y) / steps,
+ };
+
+ const current = {
+ clientX: from.x,
+ clientY: from.y,
+ };
+
+ fireEvent.mouseEnter(element, current);
+ fireEvent.mouseOver(element, current);
+ fireEvent.mouseMove(element, current);
+ fireEvent.mouseDown(element, current);
+ for (let i = 0; i < steps; i++) {
+ current.clientX += step.x;
+ current.clientY += step.y;
+ await sleep(duration / steps);
+ fireEvent.mouseMove(element, current);
+ }
+ fireEvent.mouseUp(element, current);
+}
+```
From 5723c2c9dd032e1af47761ae10d7420d8687c89b Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Thu, 11 Jun 2020 21:31:38 -0600
Subject: [PATCH 147/903] docs: add Izhaki as a contributor (#498)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index e9a6f0666..c7862a415 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -756,6 +756,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "Izhaki",
+ "name": "Izhaki",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/880132?v=4",
+ "profile": "https://github.com/Izhaki",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index d70923506..5c4a424ae 100644
--- a/README.md
+++ b/README.md
@@ -140,6 +140,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Ryan Kennel π
Jesus Hernandez π
Aaron Pettengill π
+ Izhaki π
From 75ded63acb515c1e6cef283caae742394878b578 Mon Sep 17 00:00:00 2001
From: Travis Jefferson
Date: Sun, 14 Jun 2020 10:52:15 -0400
Subject: [PATCH 148/903] Update waitForElementToBeRemoved docs
To match the recent change to its return type (and TS typedef)
Original issue: dom-testing-library issue #610
---
docs/dom-testing-library/api-async.md | 46 ++++++++++++++++-----------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/docs/dom-testing-library/api-async.md b/docs/dom-testing-library/api-async.md
index 7c7fe39b0..0eeb57e09 100644
--- a/docs/dom-testing-library/api-async.md
+++ b/docs/dom-testing-library/api-async.md
@@ -23,8 +23,8 @@ function waitFor(
): Promise
```
-When in need to wait for any period of time you can use `waitFor`, to wait for your
-expectations to pass. Here's a simple example:
+When in need to wait for any period of time you can use `waitFor`, to wait for
+your expectations to pass. Here's a simple example:
```javascript
// ...
@@ -63,24 +63,24 @@ function waitForElementToBeRemoved(
interval?: number
mutationObserverOptions?: MutationObserverInit
}
-): Promise
+): Promise
```
To wait for the removal of element(s) from the DOM you can use
`waitForElementToBeRemoved`. The `waitForElementToBeRemoved` function is a small
-wrapper around the `wait` utility.
+wrapper around the `waitFor` utility.
-The first argument must be an element, array of elements, or a callback which returns
-an element or array of elements.
+The first argument must be an element, array of elements, or a callback which
+returns an element or array of elements.
-Here is an example where the promise resolves with `true` because the element is
-removed:
+Here is an example where the promise resolves because the element is removed:
```javascript
const el = document.querySelector('div.getOuttaHere')
-waitForElementToBeRemoved(document.querySelector('div.getOuttaHere'))
- .then(() => console.log('Element no longer in DOM'))
+waitForElementToBeRemoved(document.querySelector('div.getOuttaHere')).then(() =>
+ console.log('Element no longer in DOM')
+)
el.setAttribute('data-neat', true)
// other mutations are ignored...
@@ -94,9 +94,15 @@ or an empty array:
```javascript
waitForElementToBeRemoved(null).catch(err => console.log(err))
-waitForElementToBeRemoved(queryByText(/not here/i)).catch(err => console.log(err))
-waitForElementToBeRemoved(queryAllByText(/not here/i)).catch(err => console.log(err))
-waitForElementToBeRemoved(() => getByText(/not here/i)).catch(err => console.log(err))
+waitForElementToBeRemoved(queryByText(/not here/i)).catch(err =>
+ console.log(err)
+)
+waitForElementToBeRemoved(queryAllByText(/not here/i)).catch(err =>
+ console.log(err)
+)
+waitForElementToBeRemoved(() => getByText(/not here/i)).catch(err =>
+ console.log(err)
+)
// Error: The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.
```
@@ -116,9 +122,14 @@ function wait(
}
): Promise
```
-Previously, wait was a wrapper around wait-for-expect and used polling instead of a MutationObserver to look for changes. It is now an alias to waitFor and will be removed in a future release.
-Unlike wait, the callback parameter is mandatory in waitFor. Although you can migrate an existing `wait()` call to `waitFor( () => {} )`, it is considered bad practice to use an empty callback because it will make the tests more fragile.
+Previously, wait was a wrapper around wait-for-expect and used polling instead
+of a MutationObserver to look for changes. It is now an alias to waitFor and
+will be removed in a future release.
+
+Unlike wait, the callback parameter is mandatory in waitFor. Although you can
+migrate an existing `wait()` call to `waitFor( () => {} )`, it is considered bad
+practice to use an empty callback because it will make the tests more fragile.
## `waitForDomChange` (DEPRECATED, use waitFor instead)
@@ -158,9 +169,7 @@ container.setAttribute('data-cool', 'true')
waitForDomChange({ container }).then(mutationsList => {
const mutation = mutationsList[0]
console.log(
- `was cool: ${mutation.oldValue}\ncurrently cool: ${
- mutation.target.dataset.cool
- }`
+ `was cool: ${mutation.oldValue}\ncurrently cool: ${mutation.target.dataset.cool}`
)
})
container.setAttribute('data-cool', 'false')
@@ -183,7 +192,6 @@ will detect additions and removals of child elements (including text nodes) in
the `container` and any of its descendants. It will also detect attribute
changes.
-
## `waitForElement` (DEPRECATED, use `find*` queries or `waitFor`)
```typescript
From 13fa2d4240f5c62c5d9a00a312d9371ccfccb019 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Mon, 15 Jun 2020 14:31:57 -0600
Subject: [PATCH 149/903] Update api-events.md (#501)
---
docs/dom-testing-library/api-events.md | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/docs/dom-testing-library/api-events.md b/docs/dom-testing-library/api-events.md
index 2e6f972d6..a87ff6d51 100644
--- a/docs/dom-testing-library/api-events.md
+++ b/docs/dom-testing-library/api-events.md
@@ -103,3 +103,16 @@ const myEvent = createEvent.click(node, { button: 2 })
fireEvent(node, myEvent)
// myEvent.timeStamp can be accessed just like any other properties from myEvent
```
+
+You can also create generic events:
+
+```javascript
+// simulate the 'input' event on a file input
+fireEvent(
+ input,
+ createEvent('input', input, {
+ target: {files: inputFiles},
+ ...init,
+ }),
+)
+```
From 2a69af53cf122d7c66ade5121c0a90a94b1d131b Mon Sep 17 00:00:00 2001
From: Alexander Sokolov
Date: Tue, 16 Jun 2020 09:11:22 +0300
Subject: [PATCH 150/903] Update install.md
Update `Wrappers` section with others libs defined in sidebar
---
docs/dom-testing-library/install.md | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/docs/dom-testing-library/install.md b/docs/dom-testing-library/install.md
index 7a5308c2d..77bdfb441 100644
--- a/docs/dom-testing-library/install.md
+++ b/docs/dom-testing-library/install.md
@@ -17,7 +17,17 @@ If you are using a framework or library such as React, you will likely want to
install the wrapper:
- [React Testing Library](react-testing-library/intro.md)
+- [Reason Testing Library](bs-react-testing-library/intro.md)
+- [Native Testing Library](native-testing-library/intro.md)
+- [Vue Testing Library](vue-testing-library/intro.md)
+- [Marko Testing Library](marko-testing-library/intro.md)
+- [Angular Testing Library](angular-testing-library/intro.md)
+- [Preact Testing Library](preact-testing-library/intro.md)
+- [Svelte Testing Library](svelte-testing-library/intro.md)
- [Cypress Testing Library](cypress-testing-library/intro.md)
+- [Puppeteer Testing Library](pptr-testing-library/intro.md)
+- [Testcafe Testing Library](testcafe-testing-library/intro.md)
+- [Nightwatch Testing Library](nightwatch-testing-library/intro.md)
## Ecosystem
From b467e1a7caf4c53976b2012b8628110d4d45acd0 Mon Sep 17 00:00:00 2001
From: Robin Wieruch
Date: Tue, 16 Jun 2020 15:34:42 +0200
Subject: [PATCH 151/903] Update intro.md (#504)
* Update intro.md
additional reading tutorial
* Update docs/react-testing-library/intro.md
Co-authored-by: Kent C. Dodds
Co-authored-by: Kent C. Dodds
---
docs/react-testing-library/intro.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/docs/react-testing-library/intro.md b/docs/react-testing-library/intro.md
index 055bbb337..471cb70a2 100644
--- a/docs/react-testing-library/intro.md
+++ b/docs/react-testing-library/intro.md
@@ -64,7 +64,7 @@ facilitate testing implementation details). Read more about this in
> [`DOM Testing Library`](dom-testing-library/intro.md) which is where most of
> the logic behind the queries is.
-## Video
+## Tutorials
Have a look at the "What is React Testing library?" video below for an
introduction to the library.
@@ -72,3 +72,5 @@ introduction to the library.
+
+Also, don't miss this [tutorial for React Testing Library](https://www.robinwieruch.de/react-testing-library).
From 044e3ec8db0620f549e7209d33d9887f1c3cd81f Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 16 Jun 2020 07:35:40 -0600
Subject: [PATCH 152/903] docs: add rwieruch as a contributor (#505)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 3 +++
2 files changed, 12 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index c7862a415..4c02da3f4 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -765,6 +765,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "rwieruch",
+ "name": "Robin Wieruch",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/2479967?v=4",
+ "profile": "https://www.robinwieruch.de/",
+ "contributions": [
+ "tutorial"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 5c4a424ae..b11ceeac9 100644
--- a/README.md
+++ b/README.md
@@ -142,6 +142,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Aaron Pettengill π
Izhaki π
+
+ Robin Wieruch β
+
From e658d0d189bcefa59052b832d61c0f779e6c0ec8 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Fri, 19 Jun 2020 07:14:35 +0000
Subject: [PATCH 153/903] docs: update README.md [skip ci]
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index b11ceeac9..d956c39e8 100644
--- a/README.md
+++ b/README.md
@@ -144,6 +144,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Robin Wieruch β
+ Alexander Sokolov π
From bacddb3cee10271d2b9531a2b96893684f51421d Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Fri, 19 Jun 2020 07:14:36 +0000
Subject: [PATCH 154/903] docs: update .all-contributorsrc [skip ci]
---
.all-contributorsrc | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 4c02da3f4..de5772a0e 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -774,6 +774,15 @@
"contributions": [
"tutorial"
]
+ },
+ {
+ "login": "Alex-Sokolov",
+ "name": "Alexander Sokolov",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/4497128?v=4",
+ "profile": "https://github.com/Alex-Sokolov",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
From 1cdcb247c7456c02edafd1524a9f1a492307f83e Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Fri, 19 Jun 2020 10:25:38 -0600
Subject: [PATCH 155/903] add discord server shortcut
---
netlify.toml | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/netlify.toml b/netlify.toml
index e4ed55f59..feec420e2 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -13,6 +13,13 @@
# Default build command.
command = "cd website; npm install; npm run format-docs; npm run build"
+# Shortcut to discord server invite
+[[redirects]]
+ from = "https://testing-library.com/discord"
+ to = "https://discord.gg/c6JN9fM"
+ status = 301
+ force = true
+
# React root to React landing page
[[redirects]]
from = "https://react-testing-library.com/"
From 6ca45677fcd7c91c5e571b760906a445aaa287ec Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Sat, 20 Jun 2020 11:42:09 -0400
Subject: [PATCH 156/903] Merge support page into help page (#508)
* Remove support page
* Redirect support page to help page
* Add "Want to help?" from support page to help page
---
netlify.toml | 7 +++
website/pages/en/help.js | 26 ++++++++++
website/pages/en/support.js | 100 ------------------------------------
website/siteConfig.js | 1 -
4 files changed, 33 insertions(+), 101 deletions(-)
delete mode 100644 website/pages/en/support.js
diff --git a/netlify.toml b/netlify.toml
index feec420e2..892698e1a 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -48,6 +48,13 @@
status = 301
force = false # do not redirect if route is not 404
+# Support page to help page
+[[redirects]]
+ from = "/support"
+ to = "/help"
+ status = 301
+ force = true
+
# DOM landing page to home page
[[redirects]]
from = "https://testing-library.com/dom/"
diff --git a/website/pages/en/help.js b/website/pages/en/help.js
index 7bcdc53be..3a0ccec33 100755
--- a/website/pages/en/help.js
+++ b/website/pages/en/help.js
@@ -86,6 +86,32 @@ function Help(props) {
+
+
+ Thanks! The Testing Library maintainers are happy to maintain this
+ library along with you, the community. We aren't looking for
+ funding, but we need everyone to pitch in to make this project and
+ community successful and improve tests for everyone in the long run.
+
+
+ Please consider helping us answer community questions and update
+ documentation content via the help links above. You can also help
+ support{' '}
+
+ Kent C. Dodds
+ {' '}
+ financially by purchasing his{' '}
+
+ courses
+ {' '}
+ or{' '}
+
+ remote workshops
+
+ .
+
diff --git a/website/pages/en/support.js b/website/pages/en/support.js
deleted file mode 100644
index e19726dcb..000000000
--- a/website/pages/en/support.js
+++ /dev/null
@@ -1,100 +0,0 @@
-const React = require('react')
-
-const CompLibrary = require('../../core/CompLibrary.js')
-
-const Container = CompLibrary.Container
-const GridBlock = CompLibrary.GridBlock
-
-const ExternalLink = props => (
-
-)
-const Link = props =>
-
-function Support(props) {
- const { config: siteConfig, language = '' } = props
- const { baseUrl, docsUrl } = siteConfig
- const docsPart = `${docsUrl ? `${docsUrl}/` : ''}`
- const langPart = `${language ? `${language}/` : ''}`
- const docUrl = doc => `${baseUrl}${docsPart}${langPart}${doc}`
-
- const supportLinks = [
- {
- content: `Answer a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/react-testing-library)`,
- title: 'Stack Overflow',
- },
- {
- content:
- 'Discuss issues with community members on [Spectrum](https://spectrum.chat/testing-library)',
- title: 'Spectrum',
- },
- {
- content: `Chat on [Discord](https://www.reactiflux.com/)`,
- title: 'Discord',
- },
- {
- content: `Write your own blog posts and tutorials and add them to the [learning material](${props.config.baseUrl}docs/learning) page`,
- title: 'Blog',
- },
- {
- content: `Contribute to [the project recipes](${props.config.baseUrl}docs/recipes)`,
- title: 'Recipes',
- },
- {
- content: `Watch the [GitHub repo](${props.config.repoUrl}) and respond to issues and PRs`,
- title: 'GitHub',
- },
- ]
-
- return (
-
-
-
-
-
- Thanks! The Testing Library maintainers are happy to maintain this
- library along with you, the community. We aren't looking for
- funding, but we need everyone to pitch in to make this project and
- community successful and improve tests for everyone in the long run.
- With that in mind, here are a few ways you can help support this
- effort.
-
-
-
- Buy a Course
-
-
- Kent C. Dodds
-
- , the creator of Testing Library, was able to create and maintain
- Testing Library packages thanks to license purchases of his
- TestingJavaScript.com course.
-
-
- You can support Kent by purchasing a license to{' '}
-
- TestingJavaScript.com
-
-
-
-
-
-
-
-
-
-
-
- )
-}
-
-module.exports = Support
diff --git a/website/siteConfig.js b/website/siteConfig.js
index 0d5bc0a06..2bcedb138 100755
--- a/website/siteConfig.js
+++ b/website/siteConfig.js
@@ -136,7 +136,6 @@ const siteConfig = {
{ doc: 'intro', label: 'Docs' },
{ doc: 'recipes', label: 'Recipes' },
{ page: 'help', label: 'Help' },
- { page: 'support', label: 'Support Us' },
{ blog: true, label: 'Blog' },
],
From a21702becc1a3fd3f5553a10242f627124d956e9 Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Mon, 22 Jun 2020 09:24:05 -0400
Subject: [PATCH 157/903] docs: Link to new Discord (#507)
* Link to new Discord
* Remove some Spectrum links
---
docs/contributing.md | 7 ++-----
website/core/Footer.js | 7 ++-----
website/pages/en/help.js | 2 +-
3 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/docs/contributing.md b/docs/contributing.md
index d446eacbe..65791f758 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -31,8 +31,7 @@ a π. This helps maintainers prioritize what to work on.
For questions related to using the library, please visit a support community
instead of filing an issue on GitHub.
-- [Spectrum][spectrum]
-- [Reactiflux on Discord][reactiflux]
+- [Discord][discord]
- [Stack Overflow][stackoverflow]
diff --git a/website/core/Footer.js b/website/core/Footer.js
index 774c3e766..7c14a9873 100755
--- a/website/core/Footer.js
+++ b/website/core/Footer.js
@@ -55,11 +55,8 @@ class Footer extends React.Component {
Stack Overflow
-
- Reactiflux on Discord
-
-
- Spectrum
+
+ Discord
diff --git a/website/pages/en/help.js b/website/pages/en/help.js
index 3a0ccec33..a185d7e3c 100755
--- a/website/pages/en/help.js
+++ b/website/pages/en/help.js
@@ -35,7 +35,7 @@ function Help(props) {
title: 'Spectrum',
},
{
- content: `Chat on [Discord](https://www.reactiflux.com/)`,
+ content: `Chat on [Discord](https://discord.gg/c6JN9fM)`,
title: 'Discord',
},
{
From 0a6a8407d6db47010b2a63f0d50615470cfa9a2c Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Tue, 23 Jun 2020 12:34:15 -0400
Subject: [PATCH 158/903] docs: Add iFood to users (#509)
---
website/siteConfig.js | 6 ++++++
website/static/img/users/ifood.png | Bin 0 -> 3920 bytes
2 files changed, 6 insertions(+)
create mode 100644 website/static/img/users/ifood.png
diff --git a/website/siteConfig.js b/website/siteConfig.js
index 2bcedb138..93d5d32e4 100755
--- a/website/siteConfig.js
+++ b/website/siteConfig.js
@@ -112,6 +112,12 @@ const users = [
infoLink: 'https://gusto.com/',
pinned: true,
},
+ {
+ caption: 'iFood',
+ image: '/img/users/ifood.png',
+ infoLink: 'https://www.ifood.com.br/',
+ pinned: true,
+ },
]
const siteConfig = {
diff --git a/website/static/img/users/ifood.png b/website/static/img/users/ifood.png
new file mode 100644
index 0000000000000000000000000000000000000000..ffcd582fdab4fed2787f5f7e236deec474c23c9d
GIT binary patch
literal 3920
zcmV-W53lfvP)-}|oa)ZE-ml`6$h)7BSIrTtS?qAEqx
zrI>?#r6&N_L=5`?7~z@Vt(fPo1^NKz0p|cm0X=}tzak
z26)V2=vvPNJqry;tVF)joqz)!hJFmx$2ji*;56V=Km)yiu0SU{q#K}sBYw
z`Z3Q0)1Ci;D!m=X>;V2AHK>@Gs26as!?^c>RZ)X{rF#HZ0apWqB8GPYYJvUj&vC$9
zpsGX;_)6CRM>-5$2TX_>RE!cG0t|E*H`_BoQ=tLA(nEk>A~R4D)&f%#9{X9O7h)bn
zu^4zSYEUssG!W<>F=i()v(Nxv>En^L*+n7qu@;BfuF9wM!EF_J7uXUts2C+W)M3nK
zU}3&DeWj1aO@W$`^%-O-s{uM^y+0S3daJlG2-w|W+)=cxV(@80aUm3vDqK!?=Ws2u-xT@iIm8GvA<7pti2OP1A9dbeZn)r
z>LfC%6y$KCKYI{ccD>69+al~S5V+W3+zV-6$Y&G)&@bdG
zeJHYnI~Ev>IM})&U*>isrZ*3G8<^#pU{S<1Ib&rHLT;GBNO)*ZD|;KT8o5aV;2qBd
zi%TT8E3#Z^WcS?L%G`n&$xDFm+cAY$26&zc7P!bwG7}9$0-sS^#6JPk5QTd(ri`A5
z5{0o1*%|JlMAqIq2e<$@1#zks;#~WCg|GBv;1SORGh$wAw(N6(^R4Wt**3#+U+JfT
zKX@jXl~8sK@D1Q1;0(kKQVjLT4eUe`n@Hp4W5|RdR00`=Sco_mTj47`9C!{<*fB&a
zP&R#l?*dbNrK5I@yWlH*7Vx5#JsNif0_Y1|Z)IPXK=#SN^T6ZC4OFZG0W9)N(BL{a
z$xP%DbJ+q+wRh)`1TqRS+cQDNdyTL3e!vfaZ{xP>C`2#d0bl7po(XP@8tf~50B|dC
zIg+MQ484H|eWefbOfb$tHoz_RXWt@a=kj)(!AWMK0S;r<0V|L%b!g6e#d?-Mjm7y&
z9|rstxQXHwD4Xy3N{=lxz*l-0;z_@r;uR=E4RDjM^pz2^Yk}VY_fUETDj2E?BbE~R
zO83Mq4`mTD8}&mz;13bS+EM5rOA})Bu0+=6%=%o97<_NrYdIWv0MMN|qP!=kAiE22i?4KOu9gisJ&J5lqIOwH_y|W&b%wah*)ZIc=pAGWy#lzzzE+F;
z^HH|S4B$Fo11&+qX6#ngGr?^8<^F@xFO}K!1x5k)XTRtxeF!oG9hRc({=kL6!#T2R
zfM46|N{gkWtVDx=eH_Nkv;ooez-s`$()}Fe&GJkzE#I5=PMk!#3Y4K$e9%{VFJ#x5
zrUHR%TuvfKiGVwRZ>22zUC#uO=^xp|wTT8e9Mgy_XStk?#BHJ|lsW?NQ{)3K2R*I*
zk(mYV0*)_}?9cm3e|ppTN?#1zp0dm)BxoKBXC<;u#=#ClS0FY`E`y1li9Vrl65Cn8
zwGP)%Dr#t1Qbzy8ss#t-7k4q&SdA>2wjhHO5zBR3VuGInqoWYz<7;vN)7iTdKU94+unkelD*
zn$*97{P{u}TXM$#5=@SuebU9e%nP6GmgW@RBK-_#WyLglB
zu`W3*bC4}&D{M^Y3eum>bD3>_f2R#)--hI7m4ievyf{j9G|?YqK1Wp_+|m!;$rDvS
z0r;ZB@ug%7@UqREbn()ck_IFUaxBR!VB*qOdTpP%K(#GXRmQm&gBsC^Bu1eGoH&6A_kmaZ+ZjQmFgs;hmB88IW
zWGhlkc{sbq{?euaiO3&Ad3IzO7Ll;v!BvTlB-*BFB;3cdKca+D)OjY@6!Q82WOr9i
zUa$#S{gLvdax%p;K^@`~D&scIl@_Dnt}*XJm28t;1GXZG&{
z$|x6PNx9QkdLPQ?8P8yn*6u|rk+n%&mXii@c4pSec#Olbn+SIefLou;M7s(~j6q}HjXq}c@&Z5W{
zfnV6ayHnoX=zBzvs4s4bXtT024lUhro5j`=?iv8uYNuKmVOa@W=b7Nctk+f{
zLCLgP4vftz)U2hvOZdAu)|iFiqC|a&UQ(I}w}<-Umg~HrK>L~LNIWi0J_IiDOprUJ
z&md-&Ujo)z+1YZoQaa^zInSJ8N|;=f$i=8`B)m>+7;gDTd7WJL?u_i#RRpV$FY)yd
z*=vvt#jf
zrRFW~02CFV8Ye9r{0hP+pg*hoofMAB!c5WP9rKz>ugiKv;V2X2P(9CD)X
zHlfNzi8d0kT-i*!Ybf29xefRgaIR;9HzQabT8Ke~{UXA!hHnXdHpczRKS&g)tYlY3p9tbQ6
zYhT=!*nUf=BB?Q}X=yi@nN72QXMS?uZ=&ThsPjzV+#9h{NlS@tw!fPQSE9~HhmY+c
z$8JabQ%?Z@OzHZPlJSj=Mf^iehz};;*s#|!KV5)(iP2!QQc2BER1Ch-R^g+Nwz$3)3lKqH;
z9XKkHid7;2n*)^Hy>%S$n9bU2Gi?9FehD(9xe5KRq
zUtJJi=@V^c<3x(;5-#UyHFwk`{0%bLf%@2B+x$%%qvC4pDmT@gCy0B1Wu&1&89|rCiqtg
z&)2538zlnpm42A~Er>IGol)1AdqZ
zuKG&PrKR7{E`^@$o%XOhYlTf8xf&_#i{tU_ilppzBRvJ$i3E>_=S1gU$@+VK+!Cou
zr`;(LfM{?`p7MA=xE4CHA@s>UXup;{YPm=3Q*Rnn(j
e@6M`J2LA`Jyn0z1r7z_G0000
Date: Wed, 24 Jun 2020 15:19:58 +0200
Subject: [PATCH 159/903] doc(svelte): add link to
svelte-society/recipes-mvp/testing (#510)
---
docs/svelte-testing-library/example.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/docs/svelte-testing-library/example.md b/docs/svelte-testing-library/example.md
index f241f5c98..0319b7154 100644
--- a/docs/svelte-testing-library/example.md
+++ b/docs/svelte-testing-library/example.md
@@ -50,3 +50,7 @@ test('changes button text on click', async () => {
expect(button).toHaveTextContent('Button Clicked')
})
```
+
+For additional resources, patterns and best practices about testing svelte
+components and other svelte features take a look at
+[svelte-society/recipes-mvp/testing](https://github.com/svelte-society/recipes-mvp/blob/master/testing.md).
From 732e43dc79ef706587ac4501296fc46f4782cc5b Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Wed, 24 Jun 2020 07:21:35 -0600
Subject: [PATCH 160/903] docs: add sastan as a contributor (#511)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index de5772a0e..0ec67e2e0 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -783,6 +783,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "sastan",
+ "name": "Sascha Tandel",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/514405?v=4",
+ "profile": "https://github.com/sastan",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index d956c39e8..74eea0380 100644
--- a/README.md
+++ b/README.md
@@ -145,6 +145,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Robin Wieruch β
Alexander Sokolov π
+ Sascha Tandel π
From d379e5546bd83e2f7e27da0fa32f2d77f226c078 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Wed, 24 Jun 2020 15:15:25 -0600
Subject: [PATCH 161/903] add onTimeout (#512)
---
docs/dom-testing-library/api-async.md | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/docs/dom-testing-library/api-async.md b/docs/dom-testing-library/api-async.md
index 0eeb57e09..cde04d5f6 100644
--- a/docs/dom-testing-library/api-async.md
+++ b/docs/dom-testing-library/api-async.md
@@ -18,6 +18,7 @@ function waitFor(
container?: HTMLElement
timeout?: number
interval?: number
+ onTimeout?: (error: Error) => Error
mutationObserverOptions?: MutationObserverInit
}
): Promise
@@ -46,6 +47,10 @@ before starting the intervals.
The default `timeout` is `1000ms` which will keep you under
[Jest's default timeout of `5000ms`](https://jestjs.io/docs/en/jest-object.html#jestsettimeouttimeout).
+The default `onTimeout` takes the error and appends the `container`'s printed
+state to the error message which should hopefully make it easier to track down
+what caused the timeout.
+
The default `mutationObserverOptions` is
`{subtree: true, childList: true, attributes: true, characterData: true}` which
will detect additions and removals of child elements (including text nodes) in
@@ -61,6 +66,7 @@ function waitForElementToBeRemoved(
container?: HTMLElement
timeout?: number
interval?: number
+ onTimeout?: (error: Error) => Error
mutationObserverOptions?: MutationObserverInit
}
): Promise
From 08c51b4b47813a8bf926759861e3bf847ce63ebb Mon Sep 17 00:00:00 2001
From: Gyuwon Yi
Date: Sat, 27 Jun 2020 23:03:21 +0900
Subject: [PATCH 162/903] Correct Assert section in Example page (#513)
Assert section in Example page of React Testing Library does not
contains assertion code but SUT. So rename the section to
'System Under Test' and insert a new section that describes assertion
code correctly.
---
docs/react-testing-library/example-intro.md | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/docs/react-testing-library/example-intro.md b/docs/react-testing-library/example-intro.md
index 7ef8514f5..3c692beea 100644
--- a/docs/react-testing-library/example-intro.md
+++ b/docs/react-testing-library/example-intro.md
@@ -158,6 +158,16 @@ await waitFor(() =>
### Assert
+```jsx
+// assert that the alert message is correct.
+expect(screen.getByRole('alert')).toHaveTextContent('Oops, failed to fetch!')
+
+// assert that the button is not disabled.
+expect(screen.getByRole('button')).not.toHaveAttribute('disabled')
+```
+
+### System Under Test
+
fetch.js
```jsx
From 136f19d3d4761341b272a58fedef3cf28d3f1e0b Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sat, 27 Jun 2020 08:03:57 -0600
Subject: [PATCH 163/903] docs: add gyuwon as a contributor (#514)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 0ec67e2e0..1f195a3fb 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -792,6 +792,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "gyuwon",
+ "name": "Gyuwon Yi",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/973743?v=4",
+ "profile": "https://gyuwon.github.io/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 74eea0380..768fc710b 100644
--- a/README.md
+++ b/README.md
@@ -146,6 +146,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Robin Wieruch β
Alexander Sokolov π
Sascha Tandel π
+ Gyuwon Yi π
From 2bf818974a120c6994456615f9d5fa7fd6f7dccd Mon Sep 17 00:00:00 2001
From: Daniel Afonso <35337607+danieljcafonso@users.noreply.github.com>
Date: Wed, 1 Jul 2020 14:32:04 +0100
Subject: [PATCH 164/903] Add React Hooks broke my tests, now what? EN and PT
talk
- Adds both Portuguese and English version of my React Hooks broke my tests, now what? talk
- it approaches a migration from enzyme to react testing library and does a dive into the fundamentals to use the React Testing Library
---
docs/learning.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/docs/learning.md b/docs/learning.md
index e128891f9..783478ba9 100644
--- a/docs/learning.md
+++ b/docs/learning.md
@@ -40,9 +40,10 @@ sidebar_label: Learning Material
- [How to Test Asynchronous Methods](https://www.polvara.me/posts/how-to-test-asynchronous-methods/)
by [Gpx](https://twitter.com/Gpx)
- [Writing better tests with react-testing-library](https://www.youtube.com/watch?v=O0VxvRqgm7g) by [Billy Mathews](https://twitter.com/BillRMathews)
+- [React Hooks broke my tests, now what?](https://youtu.be/p3WS9GmfX_Q) by [Daniel Afonso](https://twitter.com/danieljcafonso)
## Portuguese π§π·
- [Do Enzyme ao Testing Library](https://www.infoq.com/br/presentations/enzyme-para-react-testing-library/) by [Pablo Dinella](https://github.com/PabloDinella)
-
+- [React Hooks broke my tests, now what? (Portuguese)](https://youtu.be/t46n7REGswQ?t=99) by [Daniel Afonso](https://twitter.com/danieljcafonso)
Feel free to contribute more!
From cf3180fce32b0f9f4fee3af8be7e26365ee789af Mon Sep 17 00:00:00 2001
From: Daniel Afonso <35337607+danieljcafonso@users.noreply.github.com>
Date: Wed, 1 Jul 2020 21:41:03 +0100
Subject: [PATCH 165/903] Update learning.md
Adds empty line at the end
---
docs/learning.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/docs/learning.md b/docs/learning.md
index 783478ba9..514f3d28f 100644
--- a/docs/learning.md
+++ b/docs/learning.md
@@ -46,4 +46,5 @@ sidebar_label: Learning Material
- [Do Enzyme ao Testing Library](https://www.infoq.com/br/presentations/enzyme-para-react-testing-library/) by [Pablo Dinella](https://github.com/PabloDinella)
- [React Hooks broke my tests, now what? (Portuguese)](https://youtu.be/t46n7REGswQ?t=99) by [Daniel Afonso](https://twitter.com/danieljcafonso)
+
Feel free to contribute more!
From cd4b543a65720857d5d8eaed2d4fac29ddfd6b7f Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Fri, 3 Jul 2020 00:35:32 -0400
Subject: [PATCH 166/903] Add documentation for queryFallback
It seems like #386 hasn't been fixed yet.
---
docs/dom-testing-library/api-queries.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index 1ccdd2695..5172d9312 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -605,6 +605,7 @@ getByRole(
name?: TextMatch,
normalizer?: NormalizerFn,
selected?: boolean,
+ queryFallbacks?: boolean,
}): HTMLElement
```
@@ -710,6 +711,10 @@ cy.findByRole('dialog').should('exist')
+You may also want to select an element by any role in its fallbacks, rather than the literal value of the `role` attribute. You can use `queryFallbacks: true` to selectively enable this functionality in specific queries.
+
+> An element doesn't have multiple roles in a given environment. It has a single one. Multiple roles in the attribute are evaluated from left to right until the environment finds the first role it understands. This is useful when new roles get introduced and you want to start supporting those as well as older environments that don't understand that role (yet).
+
### `ByTestId`
> getByTestId, queryByTestId, getAllByTestId, queryAllByTestId, findByTestId,
From 4e16a0742697055239dcd0b835a1d31c2ebd62c6 Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Fri, 3 Jul 2020 05:33:47 -0400
Subject: [PATCH 167/903] Improve explanation of queryFallbacks
---
docs/dom-testing-library/api-queries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index 5172d9312..b54175b72 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -711,7 +711,7 @@ cy.findByRole('dialog').should('exist')
-You may also want to select an element by any role in its fallbacks, rather than the literal value of the `role` attribute. You can use `queryFallbacks: true` to selectively enable this functionality in specific queries.
+By default, it's assumed that the first role of each element is supported, so only the first role can be queried. If you need to query an element by any role in its fallbacks instead, you can use `queryFallbacks: true`.
> An element doesn't have multiple roles in a given environment. It has a single one. Multiple roles in the attribute are evaluated from left to right until the environment finds the first role it understands. This is useful when new roles get introduced and you want to start supporting those as well as older environments that don't understand that role (yet).
From 233da822ce5bb7d9d4d05acc2f4addfbf62baabe Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Fri, 3 Jul 2020 11:10:15 -0400
Subject: [PATCH 168/903] Update docs/dom-testing-library/api-queries.md
Co-authored-by: Sebastian Silbermann
---
docs/dom-testing-library/api-queries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index b54175b72..c84cd6a21 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -711,7 +711,7 @@ cy.findByRole('dialog').should('exist')
-By default, it's assumed that the first role of each element is supported, so only the first role can be queried. If you need to query an element by any role in its fallbacks instead, you can use `queryFallbacks: true`.
+By default, it's assumed that the first role of each element is supported, so only the first role can be queried. If you need to query an element by any of its fallback roles instead, you can use `queryFallbacks: true`.
> An element doesn't have multiple roles in a given environment. It has a single one. Multiple roles in the attribute are evaluated from left to right until the environment finds the first role it understands. This is useful when new roles get introduced and you want to start supporting those as well as older environments that don't understand that role (yet).
From 7023713117b3960885ca4d2b24b864b0169fc766 Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Fri, 3 Jul 2020 12:07:03 -0400
Subject: [PATCH 169/903] Add queryFallbacks example
---
docs/dom-testing-library/api-queries.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index c84cd6a21..e5b6f9943 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -713,6 +713,8 @@ cy.findByRole('dialog').should('exist')
By default, it's assumed that the first role of each element is supported, so only the first role can be queried. If you need to query an element by any of its fallback roles instead, you can use `queryFallbacks: true`.
+For example, `getByRole('switch')` would always match `
` because it's the first role, while `getByRole('checkbox')` would not. However, `getByRole('checkbox', { queryFallbacks: true })` would enable all fallback roles and therefore match the same element.
+
> An element doesn't have multiple roles in a given environment. It has a single one. Multiple roles in the attribute are evaluated from left to right until the environment finds the first role it understands. This is useful when new roles get introduced and you want to start supporting those as well as older environments that don't understand that role (yet).
### `ByTestId`
From 5560e6e3da7de2faf62180ed8fd46bb875b39990 Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Tue, 7 Jul 2020 08:44:47 -0400
Subject: [PATCH 170/903] Warn about literal role matching (#520)
---
docs/dom-testing-library/api-queries.md | 44 ++++++++++++++++---------
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index e5b6f9943..dc8788079 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -38,8 +38,8 @@ more than one element is found after a default timeout of `1000`ms. If you need
to find more than one element, then use `findAllBy`.
> Note, this is a simple combination of `getBy*` queries and
-> [`waitFor`](/docs/api-async#waitfor). The `findBy*` queries
-> accept the `waitFor` options as the last argument. (i.e.
+> [`waitFor`](/docs/api-async#waitfor). The `findBy*` queries accept the
+> `waitFor` options as the last argument. (i.e.
> `screen.findByText('text', queryOptions, waitForOptions)`)
### findAllBy
@@ -88,7 +88,7 @@ This method is essentially a shortcut for `console.log(prettyDOM())`. It
supports debugging the document, a single element, or an array of elements.
```javascript
-import {screen} from '@testing-library/dom'
+import { screen } from '@testing-library/dom'
document.body.innerHTML = `
test
@@ -217,7 +217,7 @@ If it is important that you query an actual `` element you can provide a
```
```js
-const inputNode = screen.getByLabelText('Username', {selector: 'input'})
+const inputNode = screen.getByLabelText('Username', { selector: 'input' })
```
### `ByPlaceholderText`
@@ -619,6 +619,10 @@ Library uses `aria-query` under the hood to find those elements by their default
ARIA roles, you can find in their docs
[which HTML Elements with inherent roles are mapped to each role](https://github.com/A11yance/aria-query#elements-to-roles).
+> Roles are matched literally by string equality, without inheriting from the
+> ARIA role hierarchy. As a result, querying a superclass role like `checkbox`
+> will not include elements with a subclass role like `switch`.
+
You can query the returned element(s) by their
[accessible name](https://www.w3.org/TR/accname-1.1/). The accessible name is
for simple cases equal to e.g. the label of a form element, or the text content
@@ -658,11 +662,11 @@ case. For example in
assertions about the `Open dialog`-button you would need to use
`getAllByRole('button', { hidden: true })`.
-The default value for `hidden` can [be configured](api-configuration#configuration).
+The default value for `hidden` can
+[be configured](api-configuration#configuration).
-Certain roles can have a selected state. You can filter the
-returned elements by their selected state
-by setting `selected: true` or `selected: false`.
+Certain roles can have a selected state. You can filter the returned elements by
+their selected state by setting `selected: true` or `selected: false`.
For example in
@@ -677,8 +681,8 @@ For example in
```
you can get the "Native"-tab by calling `getByRole('tab', { selected: true })`.
-To learn more about the selected state and which elements can
-have this state see [ARIA `aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected).
+To learn more about the selected state and which elements can have this state
+see [ARIA `aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected).
```html
...
@@ -711,11 +715,21 @@ cy.findByRole('dialog').should('exist')
-By default, it's assumed that the first role of each element is supported, so only the first role can be queried. If you need to query an element by any of its fallback roles instead, you can use `queryFallbacks: true`.
-
-For example, `getByRole('switch')` would always match `
` because it's the first role, while `getByRole('checkbox')` would not. However, `getByRole('checkbox', { queryFallbacks: true })` would enable all fallback roles and therefore match the same element.
-
-> An element doesn't have multiple roles in a given environment. It has a single one. Multiple roles in the attribute are evaluated from left to right until the environment finds the first role it understands. This is useful when new roles get introduced and you want to start supporting those as well as older environments that don't understand that role (yet).
+By default, it's assumed that the first role of each element is supported, so
+only the first role can be queried. If you need to query an element by any of
+its fallback roles instead, you can use `queryFallbacks: true`.
+
+For example, `getByRole('switch')` would always match
+`
` because it's the first role, while
+`getByRole('checkbox')` would not. However,
+`getByRole('checkbox', { queryFallbacks: true })` would enable all fallback
+roles and therefore match the same element.
+
+> An element doesn't have multiple roles in a given environment. It has a single
+> one. Multiple roles in the attribute are evaluated from left to right until
+> the environment finds the first role it understands. This is useful when new
+> roles get introduced and you want to start supporting those as well as older
+> environments that don't understand that role (yet).
### `ByTestId`
From c14e587ef570734e92356af7e1e1c4b87208a5a9 Mon Sep 17 00:00:00 2001
From: Graham Holtslander
Date: Tue, 7 Jul 2020 15:50:39 -0600
Subject: [PATCH 171/903] docs(angular): update link to Angular examples
The angular example repo was recently migrated to Nx, which broke the link from this repo to those examples
---
docs/angular-testing-library/examples.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/angular-testing-library/examples.md b/docs/angular-testing-library/examples.md
index 232ad4797..c4eee4601 100644
--- a/docs/angular-testing-library/examples.md
+++ b/docs/angular-testing-library/examples.md
@@ -60,7 +60,7 @@ describe('Counter', () => {
```
More examples can be found in the
-[GitHub project](https://github.com/testing-library/angular-testing-library/tree/master/src/app/examples).
+[GitHub project](https://github.com/testing-library/angular-testing-library/tree/master/apps/example-app/app/examples).
These examples include:
- `@Input` and `@Output` properties
From f8ad6c30310236909a2e1bb39a4443d1eac896f5 Mon Sep 17 00:00:00 2001
From: Idan Entin
Date: Wed, 15 Jul 2020 15:54:37 +0300
Subject: [PATCH 172/903] docs(ByRole): Add `{ checked: boolean }` option
(#525)
Co-authored-by: Nick McCurdy
---
docs/dom-testing-library/api-queries.md | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index dc8788079..977579ee6 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -605,6 +605,7 @@ getByRole(
name?: TextMatch,
normalizer?: NormalizerFn,
selected?: boolean,
+ checked?: boolean,
queryFallbacks?: boolean,
}): HTMLElement
```
@@ -684,6 +685,29 @@ you can get the "Native"-tab by calling `getByRole('tab', { selected: true })`.
To learn more about the selected state and which elements can have this state
see [ARIA `aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected).
+Certain roles can have a checked state. You can filter the returned elements by
+their checked state by setting `checked: true` or `checked: false`.
+
+For example in
+
+```html
+
+
+ Sugar
+ Gummy bears
+ Whipped cream
+
+
+```
+
+you can get the "Sugar" option by calling
+`getByRole('checkbox', { checked: true })`. To learn more about the checked
+state and which elements can have this state see
+[ARIA `aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked).
+
+> **Note:** Checkboxes have a "mixed" state, which is considered neither checked
+> nor unchecked (details [here](https://www.w3.org/TR/html-aam-1.0/#details-id-56)).
+
```html
...
```
From b21618816887793475bdba5b4e9583c376c0f112 Mon Sep 17 00:00:00 2001
From: Boris Serdiuk
Date: Sat, 18 Jul 2020 18:33:44 +0200
Subject: [PATCH 173/903] Add a recommendation on how to import `act` (#526)
closes #524
---
docs/react-testing-library/api.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/react-testing-library/api.md b/docs/react-testing-library/api.md
index 7bbb50932..4942c35ef 100644
--- a/docs/react-testing-library/api.md
+++ b/docs/react-testing-library/api.md
@@ -290,4 +290,4 @@ errors in your tests).
This is a light wrapper around the
[`react-dom/test-utils` `act` function](https://reactjs.org/docs/test-utils.html#act).
All it does is forward all arguments to the act function if your version of
-react supports `act`.
+react supports `act`. It is recommended to use the import from `@testing-library/react` over `react-dom/test-utils` for consistency reasons.
From 01d53fda1f01a73490a6a797ab3fc788ccbcf312 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sat, 18 Jul 2020 10:34:16 -0600
Subject: [PATCH 174/903] docs: add just-boris as a contributor (#527)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 1f195a3fb..8de06f80e 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -801,6 +801,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "just-boris",
+ "name": "Boris Serdiuk",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/812240?v=4",
+ "profile": "https://twitter.com/boriscoder",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 768fc710b..fc8a434e7 100644
--- a/README.md
+++ b/README.md
@@ -147,6 +147,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Alexander Sokolov π
Sascha Tandel π
Gyuwon Yi π
+ Boris Serdiuk π
From 0fdcc4db6fadcd5e52a6cc7197fd5d9b1818b635 Mon Sep 17 00:00:00 2001
From: balavishnuvj
Date: Wed, 22 Jul 2020 02:43:19 +0530
Subject: [PATCH 175/903] minor fixes in example-intro.md (#529)
Few minor things were missing when I was trying out.
---
docs/react-testing-library/example-intro.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/react-testing-library/example-intro.md b/docs/react-testing-library/example-intro.md
index 3c692beea..4a11892a9 100644
--- a/docs/react-testing-library/example-intro.md
+++ b/docs/react-testing-library/example-intro.md
@@ -171,7 +171,7 @@ expect(screen.getByRole('button')).not.toHaveAttribute('disabled')
fetch.js
```jsx
-import React, { useState } from 'react'
+import React, { useState, useReducer } from 'react'
import axios from 'axios'
function greetingReducer(state, action) {
@@ -182,7 +182,7 @@ function greetingReducer(state, action) {
greeting: action.greeting,
}
}
- case: 'ERROR': {
+ case 'ERROR': {
return {
error: action.error,
greeting: null
@@ -207,7 +207,7 @@ export default function Fetch({ url }) {
setButtonClicked(true)
})
.catch((error) => {
- dispatch({ type: 'ERROR' })
+ dispatch({ type: 'ERROR', error })
})
}
From ff11cc1c11056412ccc81399921deb76ac333fb8 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 21 Jul 2020 15:13:46 -0600
Subject: [PATCH 176/903] docs: add balavishnuvj as a contributor (#530)
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 8de06f80e..300bad0a6 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -810,6 +810,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "balavishnuvj",
+ "name": "balavishnuvj",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/13718688?v=4",
+ "profile": "https://github.com/balavishnuvj",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index fc8a434e7..682e97fbd 100644
--- a/README.md
+++ b/README.md
@@ -148,6 +148,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Sascha Tandel π
Gyuwon Yi π
Boris Serdiuk π
+ balavishnuvj π
From 3ed05cfbd3feb9090c6894735348e166f77c5fbf Mon Sep 17 00:00:00 2001
From: Alexander Sokolov
Date: Fri, 24 Jul 2020 17:13:19 +0300
Subject: [PATCH 177/903] Update install.md (#531)
---
docs/dom-testing-library/install.md | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/docs/dom-testing-library/install.md b/docs/dom-testing-library/install.md
index 77bdfb441..6709b6c09 100644
--- a/docs/dom-testing-library/install.md
+++ b/docs/dom-testing-library/install.md
@@ -35,6 +35,12 @@ install the wrapper:
- [user-event](ecosystem-user-event.md) browser event simulation
- [jest-dom](ecosystem-jest-dom.md) custom Jest matchers
+- [bs-jest-dom](ecosystem-bs-jest-dom.md) companion library for `bs-react-testing-library`
+- [jest-native](ecosystem-jest-native.md) companion library for `Native Testing Library`
+- [react-select-event](ecosystem-react-select-event.md) companion library for `React Testing Library`
+- [eslint-plugin-testing-library](ecosystem-eslint-plugin-testing-library.md) ESLint plugin for Testing Library
+- [eslint-plugin-jest-dom](ecosystem-eslint-plugin-jest-dom.md) ESLint plugin for Jest DOM
+- [riot-testing-library](ecosystem-riot-testing-library.md) adds APIs for working with Riot.js components
## Main Exports
From e123b04fb0cf2db0941224d8ebf53f740cd4f76f Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Fri, 24 Jul 2020 08:13:49 -0600
Subject: [PATCH 178/903] docs: add Alex-Sokolov as a contributor (#532)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
From bbdf4b453e68b48f3e5741c0ac276b5cd3b6da6b Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Mon, 27 Jul 2020 04:22:25 -0400
Subject: [PATCH 179/903] docs: update landing page redirects (#533)
* docs(preact): redirect Preact landing page to docs
* docs: Add Testcafe and Nightwatch redirects
---
netlify.toml | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/netlify.toml b/netlify.toml
index 892698e1a..fed33ac84 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -111,12 +111,10 @@
status = 301
force = true
-# Preact page. Hopefully it'll join this website eventually
-# but for now it'll be nice to be able to use the URL in content/twitter/etc.
-# and not have to worry about updating those URLs in the future.
+# Preact landing page to home page
[[redirects]]
from = "https://testing-library.com/preact/"
- to = "https://github.com/antsmartian/preact-testing-library"
+ to = "https://testing-library.com/docs/preact-testing-library/intro"
status = 301
force = true
@@ -126,3 +124,17 @@
to = "https://testing-library.com/docs/ecosystem-jest-dom"
status = 301
force = true
+
+# Testcafe landing page to home page
+[[redirects]]
+ from = "https://testing-library.com/testcafe/"
+ to = "https://testing-library.com/docs/testcafe-testing-library/intro"
+ status = 301
+ force = true
+
+# Nightwatch landing page to home page
+[[redirects]]
+ from = "https://testing-library.com/nightwatch/"
+ to = "https://testing-library.com/docs/nightwatch-testing-library/intro"
+ status = 301
+ force = true
From 1dc5f28b0c40f9c8db25cc518bf0d5503d80607f Mon Sep 17 00:00:00 2001
From: Sharmila Jesupaul
Date: Tue, 28 Jul 2020 11:18:13 -0700
Subject: [PATCH 180/903] [findByLabelText] Adds a bad example using for w/ a
non-form element (#534)
This came up at my work today. An engineer thought that a `for` attr on a `` along with a related `` `id` can be queried by `findByLabelText`.
But really, we end up with this error:
```
Timed out retrying: Found a label with the text of: Photos, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.
```
I think making that explicit in the docs would avoid future confusion.
---
docs/dom-testing-library/api-queries.md | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index 977579ee6..fb2a1fc9e 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -220,6 +220,16 @@ If it is important that you query an actual `` element you can provide a
const inputNode = screen.getByLabelText('Username', { selector: 'input' })
```
+Note that it will not work in the case where a `for` attr on a `label` matches and `id` field on a non-form element.
+
+```js
+// This case is not valid
+// for/htmlFor between label and an element that is not a form element
+
+```
+
### `ByPlaceholderText`
> getByPlaceholderText, queryByPlaceholderText, getAllByPlaceholderText,
From eb74a7d1cfa8b732bcdb8bf1c4a0bc755e7e9b1e Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 28 Jul 2020 12:18:48 -0600
Subject: [PATCH 181/903] docs: add sharmilajesupaul as a contributor (#535)
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 300bad0a6..21dc46880 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -819,6 +819,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "sharmilajesupaul",
+ "name": "Sharmila Jesupaul",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/7876997?v=4",
+ "profile": "http://jesupaul.com/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 682e97fbd..05cdbb732 100644
--- a/README.md
+++ b/README.md
@@ -149,6 +149,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Gyuwon Yi π
Boris Serdiuk π
balavishnuvj π
+ Sharmila Jesupaul π
From 78e75ae3ef3634fed36ff6f1697844c5e1597376 Mon Sep 17 00:00:00 2001
From: Matan Borenkraout
Date: Tue, 28 Jul 2020 21:37:48 +0300
Subject: [PATCH 182/903] docs(fakeTimers): Explain how to use fake timers in
testing-library (#528)
Co-authored-by: Sebastian Silbermann
---
docs/using-fake-timers.md | 49 +++++++++++++++++++++++++++++++++++++++
website/sidebars.json | 2 +-
2 files changed, 50 insertions(+), 1 deletion(-)
create mode 100644 docs/using-fake-timers.md
diff --git a/docs/using-fake-timers.md b/docs/using-fake-timers.md
new file mode 100644
index 000000000..a241e0ff1
--- /dev/null
+++ b/docs/using-fake-timers.md
@@ -0,0 +1,49 @@
+---
+id: using-fake-timers
+title: Using Fake Timers
+sidebar_label: Using Fake Timers
+---
+
+In some cases, when your code uses timers (`setTimeout`, `setInterval`,
+`clearTimeout`, `clearInterval`), your tests may become unpredictable, slow and
+flaky.
+
+To solve these problems, or if you need to rely on specific timestamps in your
+code, most testing frameworks offer the option to replace the real timers in
+your tests with fake ones. This should be used sporadically and not on a regular
+basis since using it contains some overhead.
+
+When using fake timers in your tests, all of the code inside your test uses fake
+timers.
+The common pattern to setup fake timers is usually within the `beforeEach`, for
+example:
+
+```js
+// Fake timers using Jest
+beforeEach(() => {
+ jest.useFakeTimers()
+})
+```
+
+When using fake timers, you need to remember to restore the timers after your
+test runs.
+The main reason to do that is to prevent 3rd party libraries running after your
+test finishes (e.g cleanup functions), from being coupled to your fake timers
+and use real timers instead.
+For that you usually call `useRealTimers` in `afterEach`.
+It's important to also call `runOnlyPendingTimers` before switching to real
+timers.
+This will ensure you flush all the pending timers before you switch to real
+timers. If you don't progress the timers and just switch to real timers, the
+scheduled tasks won't get executed and you'll get an unexpected behavior.
+This is mostly important for 3rd parties that schedule tasks without you being
+aware of it.
+Here's an example of doing that using jest:
+
+```js
+// Running all pending timers and switching to real timers using Jest
+afterEach(() => {
+ jest.runOnlyPendingTimers()
+ jest.useRealTimers()
+})
+```
diff --git a/website/sidebars.json b/website/sidebars.json
index be00e320c..d2dea8cb8 100755
--- a/website/sidebars.json
+++ b/website/sidebars.json
@@ -1,6 +1,6 @@
{
"docs": {
- "Getting Started": ["intro", "guiding-principles"],
+ "Getting Started": ["intro", "guiding-principles", "using-fake-timers"],
"Frameworks": [
{
"type": "subcategory",
From eaee49bf01207a3755bee5fb3dd54754915c5786 Mon Sep 17 00:00:00 2001
From: Matan Borenkraout
Date: Wed, 29 Jul 2020 16:19:14 +0300
Subject: [PATCH 183/903] fix(reactExampleIntro): Missing initialState for
useReducer in react example-intro (#538)
Closes #537
---
docs/react-testing-library/example-intro.md | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/docs/react-testing-library/example-intro.md b/docs/react-testing-library/example-intro.md
index 4a11892a9..0ea0bd15e 100644
--- a/docs/react-testing-library/example-intro.md
+++ b/docs/react-testing-library/example-intro.md
@@ -174,6 +174,11 @@ fetch.js
import React, { useState, useReducer } from 'react'
import axios from 'axios'
+const initialState = {
+ error: null,
+ greeting: null,
+}
+
function greetingReducer(state, action) {
switch (action.type) {
case 'SUCCESS': {
@@ -185,7 +190,7 @@ function greetingReducer(state, action) {
case 'ERROR': {
return {
error: action.error,
- greeting: null
+ greeting: null,
}
}
default: {
@@ -195,18 +200,22 @@ function greetingReducer(state, action) {
}
export default function Fetch({ url }) {
- const [{ error, greeting }, dispatch] = useReducer(greetingReducer)
+ const [{ error, greeting }, dispatch] = useReducer(
+ greetingReducer,
+ initialState
+ )
const [buttonClicked, setButtonClicked] = useState(false)
const fetchGreeting = async () => {
- axios.get(url)
- .then((response) => {
+ axios
+ .get(url)
+ .then(response => {
const { data } = response
const { greeting } = data
dispatch({ type: 'SUCCESS', greeting })
setButtonClicked(true)
})
- .catch((error) => {
+ .catch(error => {
dispatch({ type: 'ERROR', error })
})
}
From e02d6e0492cb9d4ff18f2474f8e1f24e4bc2a873 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?=
Date: Fri, 31 Jul 2020 01:23:20 +0200
Subject: [PATCH 184/903] Update setup.md (#539)
---
docs/react-testing-library/setup.md | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/docs/react-testing-library/setup.md b/docs/react-testing-library/setup.md
index 6202c95f0..d30187eb5 100644
--- a/docs/react-testing-library/setup.md
+++ b/docs/react-testing-library/setup.md
@@ -4,12 +4,12 @@ title: Setup
sidebar_label: Setup
---
-`React Testing Library` does not require any configuration to be used (as
-demonstrated in the example above). However, there are some things you can do
-when configuring your testing framework to reduce some boilerplate. In these
-docs we'll demonstrate configuring Jest, but you should be able to do similar
-things with [any testing framework](#using-without-jest) (React Testing Library
-does not require that you use Jest).
+`React Testing Library` does not require any configuration to be used. However,
+there are some things you can do when configuring your testing framework to
+reduce some boilerplate. In these docs we'll demonstrate configuring Jest, but
+you should be able to do similar things with
+[any testing framework](#using-without-jest) (React Testing Library does not
+require that you use Jest).
## Global Config
@@ -25,8 +25,8 @@ approach is to define a utility file that re-exports everything from
all your imports. See [below](#configuring-jest-with-test-utils) for a way to
make your test util file accessible without using relative paths.
-The example below sets up data providers using the
-[`wrapper`](api.md#wrapper) option to `render`.
+The example below sets up data providers using the [`wrapper`](api.md#wrapper)
+option to `render`.
```diff
// my-component.test.js
@@ -36,7 +36,7 @@ The example below sets up data providers using the
```js
// test-utils.js
-import React from "react"
+import React from 'react'
import { render } from '@testing-library/react'
import { ThemeProvider } from 'my-ui-lib'
import { TranslationProvider } from 'my-i18n-lib'
@@ -103,8 +103,8 @@ module.exports = {
You can define your own custom queries as described in the example in the
[Helpers API](/docs/dom-testing-library/api-helpers) documentation, or via the
-[`buildQueries`](/docs/dom-testing-library/api-helpers#buildqueries) helper. Then
-you can use them in any render call using the `queries` option. To make the
+[`buildQueries`](/docs/dom-testing-library/api-helpers#buildqueries) helper.
+Then you can use them in any render call using the `queries` option. To make the
custom queries available globally, you can add them to your custom render method
as shown below.
@@ -328,6 +328,6 @@ Or with mocha's `-r` flag:
mocha -r @testing-library/react/dont-cleanup-after-each
```
-Alternatively, you could import `@testing-library/react/pure` in all your
-tests that you don't want the `cleanup` to run and the `afterEach` won't
-be setup automatically.
+Alternatively, you could import `@testing-library/react/pure` in all your tests
+that you don't want the `cleanup` to run and the `afterEach` won't be setup
+automatically.
From 98781c5c9c55d204c7f19d91aa8958a1cd019080 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?=
Date: Fri, 31 Jul 2020 20:29:17 +0200
Subject: [PATCH 185/903] feat: reflect latest RNTL changes (#541)
---
docs/cypress-testing-library/intro.md | 35 ++--
docs/dom-testing-library/api-configuration.md | 16 +-
docs/dom-testing-library/api-events.md | 12 +-
docs/dom-testing-library/api-queries.md | 8 +-
docs/dom-testing-library/install.md | 20 +-
docs/dom-testing-library/intro.md | 6 +-
docs/dom-testing-library/setup.md | 2 +-
docs/ecosystem-jest-dom.md | 3 +-
docs/ecosystem-jest-native.md | 6 +-
docs/ecosystem-native-testing-library.md | 76 --------
docs/ecosystem-riot-testing-library.md | 17 +-
docs/example-drag.md | 65 +++----
docs/example-react-hooks-useReducer.md | 13 +-
docs/guide-disappearance.md | 6 +-
docs/intro.md | 4 +-
docs/learning.md | 12 +-
docs/native-testing-library/api.md | 171 ------------------
docs/native-testing-library/cheatsheet.md | 15 --
docs/native-testing-library/intro.md | 74 --------
docs/nightwatch-testing-library/intro.md | 2 -
.../example-intro.md | 10 +-
docs/react-native-testing-library/intro.md | 57 ++++++
.../setup.md | 21 +--
docs/react-testing-library/api.md | 3 +-
docs/react-testing-library/faq.md | 25 ++-
docs/react-testing-library/intro.md | 3 +-
docs/svelte-testing-library/api.md | 2 +-
docs/testcafe-testing-library/intro.md | 12 +-
netlify.toml | 2 +-
website/pages/en/index.js | 2 +-
website/sidebars.json | 9 +-
31 files changed, 230 insertions(+), 479 deletions(-)
delete mode 100644 docs/ecosystem-native-testing-library.md
delete mode 100644 docs/native-testing-library/api.md
delete mode 100644 docs/native-testing-library/cheatsheet.md
delete mode 100644 docs/native-testing-library/intro.md
rename docs/{native-testing-library => react-native-testing-library}/example-intro.md (80%)
create mode 100644 docs/react-native-testing-library/intro.md
rename docs/{native-testing-library => react-native-testing-library}/setup.md (71%)
diff --git a/docs/cypress-testing-library/intro.md b/docs/cypress-testing-library/intro.md
index 9c4c2e90f..10215608c 100644
--- a/docs/cypress-testing-library/intro.md
+++ b/docs/cypress-testing-library/intro.md
@@ -26,14 +26,16 @@ You can now use all of `DOM Testing Library`'s `findBy`, `findAllBy`, `queryBy`
and `queryAllBy` commands off the global `cy` object.
[See the `DOM Testing Library` docs for reference](https://testing-library.com/docs/dom-testing-library/api-queries).
-> Note: the `get*` queries are not supported because for reasonable Cypress tests you
-> need retryability and `find*` queries already support that. `query*` queries are no longer
-> necessary since v5 and will be removed in v6. `find*` fully support built-in Cypress
-> assertions (removes the only use-case for `query*`).
+> Note: the `get*` queries are not supported because for reasonable Cypress
+> tests you need retryability and `find*` queries already support that. `query*`
+> queries are no longer necessary since v5 and will be removed in v6. `find*`
+> fully support built-in Cypress assertions (removes the only use-case for
+> `query*`).
## With TypeScript
-Typings are defined in `@types/testing-library__cypress` at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__cypress),
+Typings are defined in `@types/testing-library__cypress` at
+[DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__cypress),
and should be added as follows in `tsconfig.json`:
```json
@@ -44,23 +46,30 @@ and should be added as follows in `tsconfig.json`:
}
```
-You can find [all Library definitions here](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__cypress/index.d.ts).
+You can find
+[all Library definitions here](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__cypress/index.d.ts).
## Examples
To show some simple examples (from
-[cypress/integration/query.spec.js](https://github.com/testing-library/cypress-testing-library/blob/master/cypress/integration/query.spec.js) or [cypress/integration/find.spec.js](https://github.com/testing-library/cypress-testing-library/blob/master/cypress/integration/find.spec.js)):
+[cypress/integration/query.spec.js](https://github.com/testing-library/cypress-testing-library/blob/master/cypress/integration/query.spec.js)
+or
+[cypress/integration/find.spec.js](https://github.com/testing-library/cypress-testing-library/blob/master/cypress/integration/find.spec.js)):
```javascript
-cy.findByRole('button', {name: /Jackie Chan/i}).click()
-cy.findByRole('button', {name: /Button Text/i}).should('exist')
-cy.findByRole('button', {name: /Non-existing Button Text/i}).should('not.exist')
-cy.findByLabelText(/Label text/i, {timeout: 7000}).should('exist')
+cy.findByRole('button', { name: /Jackie Chan/i }).click()
+cy.findByRole('button', { name: /Button Text/i }).should('exist')
+cy.findByRole('button', { name: /Non-existing Button Text/i }).should(
+ 'not.exist'
+)
+cy.findByLabelText(/Label text/i, { timeout: 7000 }).should('exist')
// findAllByText _inside_ a form element
-cy.get('form').findByText('button', {name: /Button Text/i}).should('exist')
+cy.get('form')
+ .findByText('button', { name: /Button Text/i })
+ .should('exist')
cy.findByRole('dialog').within(() => {
- cy.findByRole('button', {name: /confirm/i})
+ cy.findByRole('button', { name: /confirm/i })
})
```
diff --git a/docs/dom-testing-library/api-configuration.md b/docs/dom-testing-library/api-configuration.md
index dfb00cbac..3fafb6f6f 100644
--- a/docs/dom-testing-library/api-configuration.md
+++ b/docs/dom-testing-library/api-configuration.md
@@ -21,18 +21,22 @@ Configuration options:
`showOriginalStackTrace`: By default, `waitFor` will ensure that the stack trace
for errors thrown by Testing Library is cleaned up and shortened so it's easier
for you to identify the part of your code that resulted in the error (async
-stack traces are hard to debug). If you want to disable this, then set`showOriginalStackTrace` to `false`. You can also disable this for a specific
+stack traces are hard to debug). If you want to disable this, then
+set`showOriginalStackTrace` to `false`. You can also disable this for a specific
call in the options you pass to `waitFor`.
-`throwSuggestions`: (experimental) When enabled, if [better queries](https://testing-library.com/docs/guide-which-query) are available
-the test will fail and provide a suggested query to use instead. Default to `false`.
+`throwSuggestions`: (experimental) When enabled, if
+[better queries](https://testing-library.com/docs/guide-which-query) are
+available the test will fail and provide a suggested query to use instead.
+Default to `false`.
+
+To disable a suggestion for a single query just add `{suggest:false}` as an
+option.
-To disable a suggestion for a single query just add `{suggest:false}` as an option.
```js
-screen.getByTestId("foo", {suggest:false}); // will not throw a suggestion
+screen.getByTestId('foo', { suggest: false }) // will not throw a suggestion
```
-
`testIdAttribute`: The attribute used by [`getByTestId`](api-queries#bytestid)
and related queries. Defaults to `data-testid`.
diff --git a/docs/dom-testing-library/api-events.md b/docs/dom-testing-library/api-events.md
index a87ff6d51..1a7bdf6ee 100644
--- a/docs/dom-testing-library/api-events.md
+++ b/docs/dom-testing-library/api-events.md
@@ -59,10 +59,10 @@ fireEvent.change(getByLabelText(/picture/i), {
})
```
-**dataTransfer**: Drag events have a `dataTransfer` property that contains
-data transferred during the operation. As a convenience, if you provide a
-`dataTransfer` property in the `eventProperties` (second argument), then
-those properties will be added to the event.
+**dataTransfer**: Drag events have a `dataTransfer` property that contains data
+transferred during the operation. As a convenience, if you provide a
+`dataTransfer` property in the `eventProperties` (second argument), then those
+properties will be added to the event.
This should predominantly be used for testing drag and drop interactions.
@@ -111,8 +111,8 @@ You can also create generic events:
fireEvent(
input,
createEvent('input', input, {
- target: {files: inputFiles},
+ target: { files: inputFiles },
...init,
- }),
+ })
)
```
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index fb2a1fc9e..dc9bf1e1a 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -220,13 +220,14 @@ If it is important that you query an actual `` element you can provide a
const inputNode = screen.getByLabelText('Username', { selector: 'input' })
```
-Note that it will not work in the case where a `for` attr on a `label` matches and `id` field on a non-form element.
+Note that it will not work in the case where a `for` attr on a `label` matches
+and `id` field on a non-form element.
```js
// This case is not valid
// for/htmlFor between label and an element that is not a form element
```
@@ -716,7 +717,8 @@ state and which elements can have this state see
[ARIA `aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked).
> **Note:** Checkboxes have a "mixed" state, which is considered neither checked
-> nor unchecked (details [here](https://www.w3.org/TR/html-aam-1.0/#details-id-56)).
+> nor unchecked (details
+> [here](https://www.w3.org/TR/html-aam-1.0/#details-id-56)).
```html
...
diff --git a/docs/dom-testing-library/install.md b/docs/dom-testing-library/install.md
index 6709b6c09..9de4fe8ed 100644
--- a/docs/dom-testing-library/install.md
+++ b/docs/dom-testing-library/install.md
@@ -18,7 +18,7 @@ install the wrapper:
- [React Testing Library](react-testing-library/intro.md)
- [Reason Testing Library](bs-react-testing-library/intro.md)
-- [Native Testing Library](native-testing-library/intro.md)
+- [React Native Testing Library](react-native-testing-library/intro.md)
- [Vue Testing Library](vue-testing-library/intro.md)
- [Marko Testing Library](marko-testing-library/intro.md)
- [Angular Testing Library](angular-testing-library/intro.md)
@@ -35,12 +35,18 @@ install the wrapper:
- [user-event](ecosystem-user-event.md) browser event simulation
- [jest-dom](ecosystem-jest-dom.md) custom Jest matchers
-- [bs-jest-dom](ecosystem-bs-jest-dom.md) companion library for `bs-react-testing-library`
-- [jest-native](ecosystem-jest-native.md) companion library for `Native Testing Library`
-- [react-select-event](ecosystem-react-select-event.md) companion library for `React Testing Library`
-- [eslint-plugin-testing-library](ecosystem-eslint-plugin-testing-library.md) ESLint plugin for Testing Library
-- [eslint-plugin-jest-dom](ecosystem-eslint-plugin-jest-dom.md) ESLint plugin for Jest DOM
-- [riot-testing-library](ecosystem-riot-testing-library.md) adds APIs for working with Riot.js components
+- [bs-jest-dom](ecosystem-bs-jest-dom.md) companion library for
+ `bs-react-testing-library`
+- [jest-native](ecosystem-jest-native.md) companion library for
+ `React Native Testing Library`
+- [react-select-event](ecosystem-react-select-event.md) companion library for
+ `React Testing Library`
+- [eslint-plugin-testing-library](ecosystem-eslint-plugin-testing-library.md)
+ ESLint plugin for Testing Library
+- [eslint-plugin-jest-dom](ecosystem-eslint-plugin-jest-dom.md) ESLint plugin
+ for Jest DOM
+- [riot-testing-library](ecosystem-riot-testing-library.md) adds APIs for
+ working with Riot.js components
## Main Exports
diff --git a/docs/dom-testing-library/intro.md b/docs/dom-testing-library/intro.md
index 1f6eeb5ca..7d48f1867 100644
--- a/docs/dom-testing-library/intro.md
+++ b/docs/dom-testing-library/intro.md
@@ -25,9 +25,9 @@ principle is:
> [The more your tests resemble the way your software is used, the more confidence they can give you.](guiding-principles.md)
As part of this goal, the utilities this library provides facilitate querying
-the DOM in the same way the user would. Finding form elements by their label text
-(just like a user would), finding links and buttons from their text (like a user
-would), and more. It also exposes a recommended way to find elements by a
+the DOM in the same way the user would. Finding form elements by their label
+text (just like a user would), finding links and buttons from their text (like a
+user would), and more. It also exposes a recommended way to find elements by a
`data-testid` as an "escape hatch" for elements where the text content and label
do not make sense or is not practical.
diff --git a/docs/dom-testing-library/setup.md b/docs/dom-testing-library/setup.md
index dcf56fc16..7792708cf 100644
--- a/docs/dom-testing-library/setup.md
+++ b/docs/dom-testing-library/setup.md
@@ -34,5 +34,5 @@ mocha --require jsdom-global/register
```
> Note, depending on the version of Node you're running, you may also need to
-> add `core-js` and `regenerator-runtime` (if you're using babel 7) or
+> add `core-js` and `regenerator-runtime` (if you're using babel 7) or
> `babel-polyfill` (for babel 6).
diff --git a/docs/ecosystem-jest-dom.md b/docs/ecosystem-jest-dom.md
index 948b3e688..0ae2432d1 100644
--- a/docs/ecosystem-jest-dom.md
+++ b/docs/ecosystem-jest-dom.md
@@ -10,7 +10,8 @@ provides custom DOM element matchers for Jest
npm install --save-dev @testing-library/jest-dom
```
-Then follow [usage section][gh-usage] from jest-dom's documentation to add the matchers to Jest.
+Then follow [usage section][gh-usage] from jest-dom's documentation to add the
+matchers to Jest.
```jsx
diff --git a/docs/ecosystem-jest-native.md b/docs/ecosystem-jest-native.md
index 2a1ebb01f..6b3f20634 100644
--- a/docs/ecosystem-jest-native.md
+++ b/docs/ecosystem-jest-native.md
@@ -5,15 +5,15 @@ sidebar_label: jest-native
---
[`Jest Native`](https://github.com/testing-library/jest-native) is a companion
-library for `Native Testing Library` that provides custom element matchers for
-Jest.
+library for `React Native Testing Library` that provides custom element matchers
+for Jest.
```
npm install --save-dev @testing-library/jest-native
```
```javascript
-
+;
diff --git a/docs/ecosystem-native-testing-library.md b/docs/ecosystem-native-testing-library.md
deleted file mode 100644
index 9f888ffbf..000000000
--- a/docs/ecosystem-native-testing-library.md
+++ /dev/null
@@ -1,76 +0,0 @@
----
-id: ecosystem-native-testing-library
-title: Native Testing Library
-sidebar_label: native-testing-library
----
-
-Native Testing Library is a testing library for **React Native** inspired by
-`DOM Testing Library`. Because React Native does not run in a browser
-environment, the core queries are implemented independently, unlike other
-wrappers that use `DOM Testing Library` as the base. You'll find much more
-information about the library, including examples, on the project website:
-
-- [Docs](https://native-testing-library.com)
-- [Docs repo](https://github.com/bcarroll22/native-testing-library-docs)
-- [Project repo](https://github.com/bcarroll22/native-testing-library)
-
-## Installation
-
-This module should be installed in your project's `devDependencies`:
-
-```
-npm install --save-dev @testing-library/react-native
-```
-
-You will also need `react` and `react-native` installed as `dependencies` in
-order to use this project.
-
-## Example
-
-```javascript
-import React from 'react'
-import { Button, Text, TextInput, View } from 'react-native'
-import { fireEvent, render, wait } from '@testing-library/react-native'
-
-function Example() {
- const [name, setUser] = React.useState('')
- const [show, setShow] = React.useState(false)
-
- return (
-
-
- {
- // let's pretend this is making a server request, so it's async
- // (you'd want to mock this imaginary request in your unit tests)...
- setTimeout(() => {
- setShow(!show)
- }, Math.floor(Math.random() * 200))
- }}
- />
- {show && {name} }
-
- )
-}
-
-test('examples of some things', async () => {
- const { getByTestId, getByText, queryByTestId, rootInstance } = render(
-
- )
- const famousWomanInHistory = 'Ada Lovelace'
-
- const input = getByTestId('input')
- fireEvent.changeText(input, famousWomanInHistory)
-
- const button = getByText('Print Username')
- fireEvent.press(button)
-
- await wait(() => expect(queryByTestId('printed-username')).toBeTruthy())
-
- expect(getByTestId('printed-username').props.children).toBe(
- famousWomanInHistory
- )
- expect(rootInstance).toMatchSnapshot()
-})
-```
diff --git a/docs/ecosystem-riot-testing-library.md b/docs/ecosystem-riot-testing-library.md
index e633a5b0e..87dd922b2 100644
--- a/docs/ecosystem-riot-testing-library.md
+++ b/docs/ecosystem-riot-testing-library.md
@@ -3,7 +3,9 @@ id: ecosystem-riot-testing-library
title: riot-testing-library
---
-[`riot-testing-library`][gh] builds on top of [DOM Testing Library](https://github.com/testing-library/dom-testing-library) by adding APIs for working with [Riot.js](https://riot.js.org/) components.
+[`riot-testing-library`][gh] builds on top of
+[DOM Testing Library](https://github.com/testing-library/dom-testing-library) by
+adding APIs for working with [Riot.js](https://riot.js.org/) components.
```
npm install --save-dev riot-testing-library
@@ -14,19 +16,18 @@ import render, { fireEvent } from 'riot-testing-library'
import TestTag from './test.tag'
test('should show count text when rendered', () => {
- const { queryByTestId } = render(TestTag, {count: 10});
- expect(queryByTestId('count').textContent).toBe("10");
+ const { queryByTestId } = render(TestTag, { count: 10 })
+ expect(queryByTestId('count').textContent).toBe('10')
})
test('should add count when click add button text', () => {
- const { queryByTestId } = render(TestTag, {count: 1});
- expect(queryByTestId('count').textContent).toBe("1");
- fireEvent.click(queryByTestId('button'))
- expect(queryByTestId('count').textContent).toBe("2");
+ const { queryByTestId } = render(TestTag, { count: 1 })
+ expect(queryByTestId('count').textContent).toBe('1')
+ fireEvent.click(queryByTestId('button'))
+ expect(queryByTestId('count').textContent).toBe('2')
})
```
-
- [riot-testing-library on GitHub][gh]
[gh]: https://github.com/ariesjia/riot-testing-library
diff --git a/docs/example-drag.md b/docs/example-drag.md
index afa11154d..2024ebfe7 100644
--- a/docs/example-drag.md
+++ b/docs/example-drag.md
@@ -6,14 +6,15 @@ sidebar_label: Drag
> **Note**
>
-> This example only works with a real browser (not with jsdom, as it does not support `getBoundingClientRect`).
+> This example only works with a real browser (not with jsdom, as it does not
+> support `getBoundingClientRect`).
# Usage
```js
await drag(slider, {
delta: { x: -100, y: 0 },
-});
+})
```
# Kapture
@@ -23,79 +24,79 @@ await drag(slider, {
# Code
```js
-import { fireEvent } from '@testing-library/dom';
+import { fireEvent } from '@testing-library/dom'
// https://stackoverflow.com/a/53946549/1179377
function isElement(obj) {
if (typeof obj !== 'object') {
- return false;
+ return false
}
- let prototypeStr, prototype;
+ let prototypeStr, prototype
do {
- prototype = Object.getPrototypeOf(obj);
+ prototype = Object.getPrototypeOf(obj)
// to work in iframe
- prototypeStr = Object.prototype.toString.call(prototype);
+ prototypeStr = Object.prototype.toString.call(prototype)
// '[object Document]' is used to detect document
if (
prototypeStr === '[object Element]' ||
prototypeStr === '[object Document]'
) {
- return true;
+ return true
}
- obj = prototype;
+ obj = prototype
// null is the terminal of object
- } while (prototype !== null);
- return false;
+ } while (prototype !== null)
+ return false
}
function getElementClientCenter(element) {
- const { left, top, width, height } = element.getBoundingClientRect();
+ const { left, top, width, height } = element.getBoundingClientRect()
return {
x: left + width / 2,
y: top + height / 2,
- };
+ }
}
-const getCoords = (charlie) =>
- isElement(charlie) ? getElementClientCenter(charlie) : charlie;
+const getCoords = charlie =>
+ isElement(charlie) ? getElementClientCenter(charlie) : charlie
-const sleep = (ms) =>
- new Promise((resolve) => {
- setTimeout(resolve, ms);
- });
+const sleep = ms =>
+ new Promise(resolve => {
+ setTimeout(resolve, ms)
+ })
export default async function drag(
element,
{ to: inTo, delta, steps = 20, duration = 500 }
) {
- const from = getElementClientCenter(element);
+ const from = getElementClientCenter(element)
const to = delta
? {
x: from.x + delta.x,
y: from.y + delta.y,
}
- : getCoords(inTo);
+ : getCoords(inTo)
const step = {
x: (to.x - from.x) / steps,
y: (to.y - from.y) / steps,
- };
+ }
const current = {
clientX: from.x,
clientY: from.y,
- };
+ }
- fireEvent.mouseEnter(element, current);
- fireEvent.mouseOver(element, current);
- fireEvent.mouseMove(element, current);
- fireEvent.mouseDown(element, current);
+ fireEvent.mouseEnter(element, current)
+ fireEvent.mouseOver(element, current)
+ fireEvent.mouseMove(element, current)
+ fireEvent.mouseDown(element, current)
for (let i = 0; i < steps; i++) {
- current.clientX += step.x;
- current.clientY += step.y;
- await sleep(duration / steps);
- fireEvent.mouseMove(element, current);
+ current.clientX += step.x
+ current.clientY += step.y
+ await sleep(duration / steps)
+ fireEvent.mouseMove(element, current)
}
- fireEvent.mouseUp(element, current);
+ fireEvent.mouseUp(element, current)
}
```
diff --git a/docs/example-react-hooks-useReducer.md b/docs/example-react-hooks-useReducer.md
index 954c67efa..55ad3a981 100644
--- a/docs/example-react-hooks-useReducer.md
+++ b/docs/example-react-hooks-useReducer.md
@@ -3,11 +3,12 @@ id: example-react-hooks-useReducer
title: useReducer
---
-Basic example showing how to test the `useReducer` hook.
-The most important thing is that we aren't testing the reducer directly - it's an
-implementation detail of the component! Instead we are testing the component interface.
+Basic example showing how to test the `useReducer` hook. The most important
+thing is that we aren't testing the reducer directly - it's an implementation
+detail of the component! Instead we are testing the component interface.
-The component we are testing changes some text depending on an `isConfirmed` state.
+The component we are testing changes some text depending on an `isConfirmed`
+state.
```jsx
// example.js
@@ -50,8 +51,8 @@ const Example = () => {
export default Example
```
-We are testing to see if we get the correct output in our JSX
-based on the reducer state.
+We are testing to see if we get the correct output in our JSX based on the
+reducer state.
```jsx
// example.test.js
diff --git a/docs/guide-disappearance.md b/docs/guide-disappearance.md
index 6ccf1194f..f884c2a3f 100644
--- a/docs/guide-disappearance.md
+++ b/docs/guide-disappearance.md
@@ -43,9 +43,9 @@ Using
[`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
is more efficient than polling the DOM at regular intervals with `waitFor`.
-The `waitFor` [async helper][async-api] function retries until the wrapped function
-stops throwing an error. This can be used to assert that an element disappears
-from the page.
+The `waitFor` [async helper][async-api] function retries until the wrapped
+function stops throwing an error. This can be used to assert that an element
+disappears from the page.
```jsx
test('movie title goes away', async () => {
diff --git a/docs/intro.md b/docs/intro.md
index e5e99f9fb..b437f179a 100644
--- a/docs/intro.md
+++ b/docs/intro.md
@@ -29,7 +29,7 @@ it.
The core library has been wrapped to provide ergonomic APIs for several
frameworks, including [React][react], [Angular][angular], and [Vue][vue]. There
is also a plugin to use testing-library queries for end-to-end tests in
-[Cypress][cypress] and an implementation for [React Native][native].
+[Cypress][cypress] and an implementation for [React Native][react-native].
### What this library is not
@@ -46,5 +46,5 @@ Jest, Mocha + JSDOM, or a real browser
[angular]: angular-testing-library/intro.md
[vue]: vue-testing-library/intro.md
[cypress]: cypress-testing-library/intro.md
-[native]: ecosystem-native-testing-library.md
+[react-native]: react-native-testing-library/intro.md
[npm]: https://www.npmjs.com/org/testing-library
diff --git a/docs/learning.md b/docs/learning.md
index 514f3d28f..7f7433129 100644
--- a/docs/learning.md
+++ b/docs/learning.md
@@ -39,12 +39,16 @@ sidebar_label: Learning Material
by [Scott Sauber](https://github.com/scottsauber)
- [How to Test Asynchronous Methods](https://www.polvara.me/posts/how-to-test-asynchronous-methods/)
by [Gpx](https://twitter.com/Gpx)
-- [Writing better tests with react-testing-library](https://www.youtube.com/watch?v=O0VxvRqgm7g) by [Billy Mathews](https://twitter.com/BillRMathews)
-- [React Hooks broke my tests, now what?](https://youtu.be/p3WS9GmfX_Q) by [Daniel Afonso](https://twitter.com/danieljcafonso)
+- [Writing better tests with react-testing-library](https://www.youtube.com/watch?v=O0VxvRqgm7g)
+ by [Billy Mathews](https://twitter.com/BillRMathews)
+- [React Hooks broke my tests, now what?](https://youtu.be/p3WS9GmfX_Q) by
+ [Daniel Afonso](https://twitter.com/danieljcafonso)
## Portuguese π§π·
-- [Do Enzyme ao Testing Library](https://www.infoq.com/br/presentations/enzyme-para-react-testing-library/) by [Pablo Dinella](https://github.com/PabloDinella)
-- [React Hooks broke my tests, now what? (Portuguese)](https://youtu.be/t46n7REGswQ?t=99) by [Daniel Afonso](https://twitter.com/danieljcafonso)
+- [Do Enzyme ao Testing Library](https://www.infoq.com/br/presentations/enzyme-para-react-testing-library/)
+ by [Pablo Dinella](https://github.com/PabloDinella)
+- [React Hooks broke my tests, now what? (Portuguese)](https://youtu.be/t46n7REGswQ?t=99)
+ by [Daniel Afonso](https://twitter.com/danieljcafonso)
Feel free to contribute more!
diff --git a/docs/native-testing-library/api.md b/docs/native-testing-library/api.md
deleted file mode 100644
index 20bf4ab8a..000000000
--- a/docs/native-testing-library/api.md
+++ /dev/null
@@ -1,171 +0,0 @@
----
-id: api
-title: API
-sidebar_label: API
----
-
-Here you'll find a high level summary of the most frequently used parts of
-Native Testing Library. For a more comprehensive look at what's possible, check
-out the [main docs site](https://native-testing-library.com).
-
-- [`render`](#render)
-- [`act`](#act)
-
-## `render`
-
-```typescript
-function render(
- ui: React.ReactElement,
- options?: {
- /* You won't often use this, expand below for docs on options */
- }
-): RenderResult
-```
-
-Create a `ReactTestRenderer` Instance.
-
-```jsx
-import { render } from '@testing-library/react-native'
-
-render( )
-```
-
-```javascript
-import { render } from '@testing-library/react-native'
-
-test('renders a message', () => {
- const { container, getByText } = render(Hello, World! )
- expect(getByText('Hello, world!')).toBeTruthy()
- expect(container.toJSON()).toMatchInlineSnapshot(`
- Hello, World!
- `)
-})
-```
-
-## `render` Options
-
-Most of the time you won't need to pass any options to `render`, but when you
-do, you will pass them as the second parameter. There are some important key
-differences between this and `React Testing Library` that you will want to be
-aware of.
-
-### `wrapper`
-
-Pass a React Component as the `wrapper` option to have it rendered around the
-inner element. This is most useful for creating reusable custom render functions
-for common data providers. See [setup](setup.md#custom-render) for examples.
-
-### `queries`
-
-Queries to bind. Overrides the default set from `Native Testing Library` unless
-merged.
-
-```js
-// Example, a function to traverse table contents
-import * as tableQueries from 'my-table-query-libary'
-import queries from '@testing-library/react-native'
-
-const { getByRowColumn, getByText } = render( , {
- queries: { ...queries, ...tableQueries },
-})
-```
-
-See [helpers](https://www.native-testing-library.com/docs/api-helpers) for
-guidance on using utility functions to create custom queries.
-
-Custom queries can also be added globally by following the
-[custom render guide](setup.md#custom-render).
-
-## `render` Result
-
-The `render` method returns an object that has a few properties:
-
-### `...queries`
-
-The most important feature of `render` is that the
-[default queries](https://www.native-testing-library.com/docs/api-queries) are
-automatically returned with their first argument bound to the `baseElement`.
-
-**Example**
-
-```javascript
-const { getByText, getByTestId /* etc */ } = render( )
-```
-
-### `container`
-
-The `ReactTestRendererInstance` result from your render. This has helpful
-methods like `toTree()` and `toJSON()`.
-
-> You should rarely use the container. There are very few instances where you
-> need to access the container itself to do something you'd need to in a test.
-
-### `baseElement`
-
-This is the root element of your render result. By default, this is what all of
-your queries will be run on, and you could also use it to do any custom
-searching logic you wanted to..
-
-### `debug`
-
-This method is a shortcut for `console.log(prettyPrint(container.toJSON()))`.
-
-```javascript
-import { render } from '@testing-library/react-native'
-
-const { debug } = render(
-
- Hello World
-
-)
-debug()
-//
-//
-// Hello World
-//
-//
-```
-
-This is a simple wrapper around `prettyPrint` which is also exported.
-
-### `rerender`
-
-Although its likely better to test updating your props the way a user would
-(through events and interaction), this method will allow you to re-render your
-entire tree at the base with new props.
-
-```jsx
-import { render } from '@testing-library/react-native'
-
-const { rerender } = render( )
-
-// re-render the same component with different props
-rerender( )
-```
-
-[See the examples page](example-update-props.md)
-
-### `unmount`
-
-This will cause the rendered component to be unmounted. This is useful for
-testing what happens when your component is removed from the page (like testing
-that you don't leave event handlers hanging around causing memory leaks). Note
-that you don't need to call this `afterEach` like you do in react testing
-library because these elements aren't being added to a DOM. Use it only as
-necessary.
-
-> This method is a wrapper around ReactTestRenderer.unmount()
-
-```javascript
-import { render } from '@testing-library/react-native'
-
-const { unmount } = render( )
-unmount()
-```
-
-## `act`
-
-This is a light wrapper around the
-[`react-test-renderer` `act` function](https://reactjs.org/docs/test-renderer.html).
-All it does is forward all arguments to the act function if your version of
-react supports `act`.
diff --git a/docs/native-testing-library/cheatsheet.md b/docs/native-testing-library/cheatsheet.md
deleted file mode 100644
index 1627524bf..000000000
--- a/docs/native-testing-library/cheatsheet.md
+++ /dev/null
@@ -1,15 +0,0 @@
----
-id: cheat-sheet
-title: Printable Cheat Sheet
-sidebar_label: Cheat Sheet
----
-
-There is a printable one-page cheat sheet available for you to download. It is
-intended to be a quick reference for `Native Testing Library`, but is not a
-complete API glossary or guide. Keep a copy of it on your desk to quickly take a
-peek at the most commonly used functionality!
-
-[Download the cheat sheet][cheatsheet]
-
-[cheatsheet]:
- https://github.com/testing-library/native-testing-library/raw/master/other/cheat-sheet.pdf
diff --git a/docs/native-testing-library/intro.md b/docs/native-testing-library/intro.md
deleted file mode 100644
index dd44f56d0..000000000
--- a/docs/native-testing-library/intro.md
+++ /dev/null
@@ -1,74 +0,0 @@
----
-id: intro
-title: Introduction
-sidebar_label: Introduction
----
-
-Native Testing Library is a testing library for **React Native** inspired by
-`DOM Testing Library`. Because React Native does not run in a browser
-environment, the core queries are implemented independently, unlike other
-wrappers that use `DOM Testing Library` as the base. You'll find much more
-information about the library, including examples, on the project sites:
-
-- [Docs][docs]
-- [Docs repo][docs-repo]
-- [Project repo][gh]
-
-## Quickstart
-
-```
-npm install --save-dev @testing-library/react-native
-```
-
-- [Native Testing Library on GitHub][gh]
-
-[docs]: https://native-testing-library.com
-[gh]: https://github.com/testing-library/native-testing-library
-[docs-repo]: https://github.com/testing-library/native-testing-library-docs
-
-## The problem
-
-You want to write maintainable tests for your React Native application. You love
-testing library, and you want to be able to write maintainable tests for your
-React Native application also. You don't want to use a library that renders
-components to a fake DOM, and you've had a hard time finding what you need to
-write tests using that philosophy in React Native.
-
-## This solution
-
-`Native Testing Library` is an implementation of the well-known
-`testing-library` API that works for React Native. The primary goal is to mimic
-the testing library API as closely as possible while still accounting for the
-differences in the platforms. Accomplishing this is no small feat because of the
-differences between the two platforms. Although most framework implementations
-like `React Testing Library` are thin layers over `DOM Testing Library`, this
-library needed to have its own base implementation as well as a user-facing API.
-This library uses the
-[react-test-renderer](https://reactjs.org/docs/test-renderer.html), whereas
-`DOM Testing Library` uses ReactDOM and JSDOM. The main philosophy is that you
-should find elements that are on the "screen" the way users would. This approach
-is meant to give you confidence that your app is working as a cohesive unit.
-Just like the `DOM Testing Library`, `Native Testing Library`'s primary guiding
-principle is:
-
-> [The more your tests resemble the way your software is used, the more confidence they can give you.](guiding-principles.md)
-
-This library gives you the tools you need to find things in your application the
-way your users would. You can do things like find elements by text, input value,
-and accessibility labels -- the types of things your users can see. We also give
-you the ability to search for elements by `testID`, but you should consider it a
-last resort because users can't see a testID and it can introduce unpredictable
-behavior in your tests.
-
-It will also encourage you to build more accessible apps. For example, your
-users can't see your icon touchable that doesn't have an accessibility label, so
-neither can your tests. We believe that writing good tests using this library
-will force you to give more consideration to whether what you're doing is an
-accessible experience for all of your users.
-
-This library should, in theory, work with any any testing framework like Jest or
-Mocha, but we do recommend you use Jest with the `react-native` Jest preset. We
-have not tested it in any other environment, and likely won't be able to support
-usage with another library.
-
-[jest]: https://jestjs.io
diff --git a/docs/nightwatch-testing-library/intro.md b/docs/nightwatch-testing-library/intro.md
index 19c9fdc09..0e726f9bc 100644
--- a/docs/nightwatch-testing-library/intro.md
+++ b/docs/nightwatch-testing-library/intro.md
@@ -3,11 +3,9 @@ id: intro
title: Nightwatch Testing Library
---
-
[`nightwatch-testing-library`][gh] allows the use of dom-testing-library queries
in [Nightwatch](https://nightwatchjs.org) for end-to-end web testing.
-
## Install
> Be sure to follow the
diff --git a/docs/native-testing-library/example-intro.md b/docs/react-native-testing-library/example-intro.md
similarity index 80%
rename from docs/native-testing-library/example-intro.md
rename to docs/react-native-testing-library/example-intro.md
index ffb54fde5..414223a03 100644
--- a/docs/native-testing-library/example-intro.md
+++ b/docs/react-native-testing-library/example-intro.md
@@ -7,7 +7,7 @@ sidebar_label: Example
```javascript
import React from 'react'
import { Button, Text, TextInput, View } from 'react-native'
-import { fireEvent, render, wait } from '@testing-library/react-native'
+import { fireEvent, render, waitFor } from '@testing-library/react-native'
function Example() {
const [name, setUser] = React.useState('')
@@ -32,9 +32,7 @@ function Example() {
}
test('examples of some things', async () => {
- const { getByTestId, getByText, queryByTestId, baseElement } = render(
-
- )
+ const { getByTestId, getByText, queryByTestId, toJSON } = render( )
const famousWomanInHistory = 'Ada Lovelace'
const input = getByTestId('input')
@@ -43,11 +41,11 @@ test('examples of some things', async () => {
const button = getByText('Print Username')
fireEvent.press(button)
- await wait(() => expect(queryByTestId('printed-username')).toBeTruthy())
+ await waitFor(() => expect(queryByTestId('printed-username')).toBeTruthy())
expect(getByTestId('printed-username').props.children).toBe(
famousWomanInHistory
)
- expect(baseElement).toMatchSnapshot()
+ expect(toJSON).toMatchSnapshot()
})
```
diff --git a/docs/react-native-testing-library/intro.md b/docs/react-native-testing-library/intro.md
new file mode 100644
index 000000000..d83f42375
--- /dev/null
+++ b/docs/react-native-testing-library/intro.md
@@ -0,0 +1,57 @@
+---
+id: intro
+title: Introduction
+sidebar_label: Introduction
+---
+
+React Native Testing Library is a testing library for **React Native** inspired
+by `React Testing Library`. Because React Native does not run in a browser
+environment, the core queries are implemented independently, unlike other
+wrappers that use `DOM Testing Library` as the base. You'll find much more
+information about the library, including examples, on the project sites:
+
+- [Docs][docs]
+- [Project repo][gh]
+
+The project is maintained by [Callstack](callstack) which is one of the React
+Native [Partners](rn-partners), active throughout the React Native Community.
+
+## Quickstart
+
+```
+npm install --save-dev @testing-library/react-native
+```
+
+- [React Native Testing Library on GitHub][gh]
+
+[docs]: https://callstack.github.io/react-native-testing-library/
+[gh]: https://github.com/callstack/react-native-testing-library
+[callstack]:
+ https://callstack.com/open-source/?utm_source=testing-library.com&utm_medium=referral&utm_campaign=react-native-testing-library
+[rn-partners]:
+ https://github.com/facebook/react-native/blob/d48f7ba748a905818e8c64fe70fe5b24aa098b05/ECOSYSTEM.md#partners
+
+## The problem
+
+You want to write maintainable tests for your React Native components. As a part
+of this goal, you want your tests to avoid including implementation details of
+your components and rather focus on making your tests give you the confidence
+for which they are intended. As part of this, you want your testbase to be
+maintainable in the long run so refactors of your components (changes to
+implementation but not functionality) don't break your tests and slow you and
+your team down.
+
+## This solution
+
+The React Native Testing Library (RNTL) is a lightweight solution for testing
+React Native components. It provides light utility functions on top of
+`react-test-renderer`, in a way that encourages better testing practices. Its
+primary guiding principle is:
+
+> The more your tests resemble the way your software is used, the more
+> confidence they can give you.
+
+This Project is tested to work with Jest, but it should work with other test
+runners as well.
+
+[jest]: https://jestjs.io
diff --git a/docs/native-testing-library/setup.md b/docs/react-native-testing-library/setup.md
similarity index 71%
rename from docs/native-testing-library/setup.md
rename to docs/react-native-testing-library/setup.md
index 8c9770e33..25db44442 100644
--- a/docs/native-testing-library/setup.md
+++ b/docs/react-native-testing-library/setup.md
@@ -6,25 +6,20 @@ sidebar_label: Setup
## Setting up your project
-The `Native Testing Library` API should work out of the box for most tests. All
-of the snippets you'll find throughout the website work without any additional
-configuration assuming you use Jest and a moderately recent version of React
-Native.
-
-We strongly encourage you to use Jest with the `@testing-library/react-native` preset.
-The `react-native` preset should also work, but you'll be getting the best
-experience when using our preset. There may be some additional mocks you need to
-provide to such as mocks for `react-native-gesture-handler` when using
-`react-navigation`.
+The `React Native Testing Library` API should work out of the box for most
+tests. All of the snippets you'll find throughout the website work without any
+additional configuration assuming you use Jest and a moderately recent version
+of React Native.
## Custom Render
It's often useful to define a custom render method that includes things like
global context providers, data stores, etc. To make this available globally, one
approach is to define a utility file that re-exports everything from
-`Native Testing Library`. You can replace `Native Testing Library` with this
-file in all your imports. See [below](#configuring-jest-with-test-utils) for a
-way to make your test util file accessible without using relative paths.
+`React Native Testing Library`. You can replace `React Native Testing Library`
+with this file in all your imports. See
+[below](#configuring-jest-with-test-utils) for a way to make your test util file
+accessible without using relative paths.
The example below sets up data providers using the
[`wrapper`](api-render.md#render-options) option to `render`.
diff --git a/docs/react-testing-library/api.md b/docs/react-testing-library/api.md
index 4942c35ef..09778ac46 100644
--- a/docs/react-testing-library/api.md
+++ b/docs/react-testing-library/api.md
@@ -290,4 +290,5 @@ errors in your tests).
This is a light wrapper around the
[`react-dom/test-utils` `act` function](https://reactjs.org/docs/test-utils.html#act).
All it does is forward all arguments to the act function if your version of
-react supports `act`. It is recommended to use the import from `@testing-library/react` over `react-dom/test-utils` for consistency reasons.
+react supports `act`. It is recommended to use the import from
+`@testing-library/react` over `react-dom/test-utils` for consistency reasons.
diff --git a/docs/react-testing-library/faq.md b/docs/react-testing-library/faq.md
index cc9429ef1..4e34004b4 100644
--- a/docs/react-testing-library/faq.md
+++ b/docs/react-testing-library/faq.md
@@ -30,16 +30,21 @@ test('change values via the fireEvent.change method', () => {
test('select drop-downs must use the fireEvent.change', () => {
const handleChange = jest.fn()
- const { container } = render(1 2 )
- const select = container.firstChild;
- const option1 = container.getElementsByTagName("option").item(0);
- const option2 = container.getElementsByTagName("option").item(1);
-
- fireEvent.change(select, {target: {value: "2"}});
-
- expect(handleChange).toHaveBeenCalledTimes(1);
- expect(option1.selected).toBe(false);
- expect(option2.selected).toBe(true);
+ const { container } = render(
+
+ 1
+ 2
+
+ )
+ const select = container.firstChild
+ const option1 = container.getElementsByTagName('option').item(0)
+ const option2 = container.getElementsByTagName('option').item(1)
+
+ fireEvent.change(select, { target: { value: '2' } })
+
+ expect(handleChange).toHaveBeenCalledTimes(1)
+ expect(option1.selected).toBe(false)
+ expect(option2.selected).toBe(true)
})
test('checkboxes (and radios) must use fireEvent.click', () => {
diff --git a/docs/react-testing-library/intro.md b/docs/react-testing-library/intro.md
index 471cb70a2..4070b7c3b 100644
--- a/docs/react-testing-library/intro.md
+++ b/docs/react-testing-library/intro.md
@@ -73,4 +73,5 @@ introduction to the library.
-Also, don't miss this [tutorial for React Testing Library](https://www.robinwieruch.de/react-testing-library).
+Also, don't miss this
+[tutorial for React Testing Library](https://www.robinwieruch.de/react-testing-library).
diff --git a/docs/svelte-testing-library/api.md b/docs/svelte-testing-library/api.md
index 03741ac94..ab195091b 100644
--- a/docs/svelte-testing-library/api.md
+++ b/docs/svelte-testing-library/api.md
@@ -71,7 +71,7 @@ const { results } = render(YourComponent, { myProp: 'value' })
| `debug` | Logs the `container` using [prettyDom](https://testing-library.com/docs/dom-testing-library/api-helpers#prettydom). |
| `unmount` | Unmounts the component from the `target` by calling `component.$destroy()`. |
| `rerender` | Calls render again destroying the old component, and mounting the new component on the original `target` with any new options passed in. |
-| `...queries` | Returns all [query functions](https://testing-library.com/docs/dom-testing-library/api-queries) that are bound to the `container`. If you pass in `query` arguments than this will be those, otherwise all. |
+| `...queries` | Returns all [query functions](https://testing-library.com/docs/dom-testing-library/api-queries) that are bound to the `container`. If you pass in `query` arguments than this will be those, otherwise all. |
## `cleanup`
diff --git a/docs/testcafe-testing-library/intro.md b/docs/testcafe-testing-library/intro.md
index 3752c0d32..b3d7b9014 100644
--- a/docs/testcafe-testing-library/intro.md
+++ b/docs/testcafe-testing-library/intro.md
@@ -35,8 +35,8 @@ Add the following to your .testcaferc.json file:
],
```
-You can now import `screen` which has all the get[All]By*, query[All]By*, find[All]By\* selectors that you can use in
-your tests.
+You can now import `screen` which has all the get[All]By*, query[All]By*,
+find[All]By\* selectors that you can use in your tests.
`import { screen } from '@testing-library/testcafe'`
@@ -76,7 +76,9 @@ test('getByLabelText', async t => {
test('queryAllByText', async t => {
await t.expect(screen.queryAllByText('Button Text').exists).ok()
- await t.expect(screen.queryAllByText('Non-existing Button Text').exists).notOk()
+ await t
+ .expect(screen.queryAllByText('Non-existing Button Text').exists)
+ .notOk()
})
```
@@ -156,7 +158,9 @@ fixture`within`.page`http://localhost:13370`
test('works with getBy* selectors', async t => {
await t
- .expect(within(screen.getByTestId('nested')).getByText('Button Text').exists)
+ .expect(
+ within(screen.getByTestId('nested')).getByText('Button Text').exists
+ )
.ok()
})
diff --git a/netlify.toml b/netlify.toml
index fed33ac84..1db9c9f94 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -72,7 +72,7 @@
# React Native landing page to home page
[[redirects]]
from = "https://testing-library.com/react-native/"
- to = "https://testing-library.com/docs/native-testing-library/intro"
+ to = "https://testing-library.com/docs/react-native-testing-library/intro"
status = 301
force = true
diff --git a/website/pages/en/index.js b/website/pages/en/index.js
index 6604e5105..14ef60144 100755
--- a/website/pages/en/index.js
+++ b/website/pages/en/index.js
@@ -233,7 +233,7 @@ class Index extends React.Component {
image: `${baseUrl}img/react-native-128x128.png`,
imageAlign: 'top',
title:
- '[Native Testing Library](./docs/native-testing-library/intro)',
+ '[React Native Testing Library](./docs/react-native-testing-library/intro)',
},
{
image: `${baseUrl}img/preact-128x128.png`,
diff --git a/website/sidebars.json b/website/sidebars.json
index d2dea8cb8..6dadf9981 100755
--- a/website/sidebars.json
+++ b/website/sidebars.json
@@ -41,12 +41,11 @@
},
{
"type": "subcategory",
- "label": "Native Testing Library",
+ "label": "React Native Testing Library",
"ids": [
- "native-testing-library/intro",
- "native-testing-library/example-intro",
- "native-testing-library/setup",
- "native-testing-library/api"
+ "react-native-testing-library/intro",
+ "react-native-testing-library/example-intro",
+ "react-native-testing-library/setup"
]
},
{
From 3bc7d388c6c36be06441272f4378dccf0ff8d931 Mon Sep 17 00:00:00 2001
From: Batuhan Wilhelm
Date: Sun, 2 Aug 2020 16:46:05 +0300
Subject: [PATCH 186/903] Add typescript section to svelte docs to clarify
usage with Typescript (#542)
* Add typescript section
* Remove unnecessary characters
---
docs/svelte-testing-library/setup.md | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/docs/svelte-testing-library/setup.md b/docs/svelte-testing-library/setup.md
index 02bf0e418..65a248495 100644
--- a/docs/svelte-testing-library/setup.md
+++ b/docs/svelte-testing-library/setup.md
@@ -72,6 +72,23 @@ with any testing framework and runner you're comfortable with.
npm run test
```
+## Typescript
+
+In order to support Typescript, you need to enable `preprocess`.
+
+1. Update your jest configuration
+
+ ```json
+ {
+ "jest": {
+ "transform": {
+ "^.+\\.svelte$": ["svelte-jester", { "preprocess": true }]
+ },
+ "moduleFileExtensions": ["js", "ts", "svelte"]
+ }
+ }
+ ```
+
## Babel / Preprocessors
If you'd like to also include [Babel](https://babeljs.io/) or any
From c383b44b4c9076d156b3a5c802f51cf1a4f867c5 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 2 Aug 2020 07:53:22 -0600
Subject: [PATCH 187/903] docs: add BatuhanW as a contributor (#544)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 3 +++
2 files changed, 12 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 21dc46880..ec5fc21ee 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -828,6 +828,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "BatuhanW",
+ "name": "Batuhan Wilhelm",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/16444991?v=4",
+ "profile": "https://github.com/BatuhanW",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 05cdbb732..dc3aa9b06 100644
--- a/README.md
+++ b/README.md
@@ -151,6 +151,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
balavishnuvj π
Sharmila Jesupaul π
+
+ Batuhan Wilhelm π
+
From 48d180aa5d6239268d6df1ac59a1a9b80f04516c Mon Sep 17 00:00:00 2001
From: Dennis Kaffer
Date: Sun, 2 Aug 2020 22:26:46 -0300
Subject: [PATCH 188/903] docs(example-reach-router): add example of route with
parameters (#545)
---
docs/example-reach-router.md | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/docs/example-reach-router.md b/docs/example-reach-router.md
index 1767c3823..bd607fde2 100644
--- a/docs/example-reach-router.md
+++ b/docs/example-reach-router.md
@@ -72,4 +72,35 @@ test('landing on a bad page', () => {
// normally I'd use a data-testid, but just wanted to show this is also possible
expect(container.innerHTML).toMatch('No match')
})
+
+// If your route component has parameters, you'll have to change the render function a little bit
+// example of a route component with parameter
+const Routes = () => (
+
+
+
+)
+
+// render function with Router wrapper from @reach/router
+function renderWithRouterWrapper(
+ ui,
+ { route = '/', history = createHistory(createMemorySource(route)) } = {}
+) {
+ return {
+ ...render(
+
+ {ui}
+
+ ),
+ history,
+ }
+}
+
+test('renders the component with params', () => {
+ // you'll have to declare the path prop in the component, exactly like the route
+ renderWithRouterWrapper( , {
+ // and pass the parameter value on the route config
+ route: '/some-component/1',
+ })
+})
```
From eb88b31411ad05dd5bc8508d0f5e9fcfad5d5883 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 2 Aug 2020 19:27:10 -0600
Subject: [PATCH 189/903] docs: add deadkff01 as a contributor (#546)
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index ec5fc21ee..398821f4f 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -837,6 +837,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "deadkff01",
+ "name": "Dennis Kaffer",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/5138179?v=4",
+ "profile": "https://github.com/deadkff01",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index dc3aa9b06..9ecdfb0ab 100644
--- a/README.md
+++ b/README.md
@@ -153,6 +153,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Batuhan Wilhelm π
+ Dennis Kaffer π
From 39e697cc713a0dd3e7194a50262b4910a4d37f14 Mon Sep 17 00:00:00 2001
From: Cam Jackson
Date: Sun, 2 Aug 2020 22:00:37 +1000
Subject: [PATCH 190/903] docs(svelte): add reference to typescript
---
docs/svelte-testing-library/setup.md | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/docs/svelte-testing-library/setup.md b/docs/svelte-testing-library/setup.md
index 65a248495..c434db92e 100644
--- a/docs/svelte-testing-library/setup.md
+++ b/docs/svelte-testing-library/setup.md
@@ -74,20 +74,10 @@ with any testing framework and runner you're comfortable with.
## Typescript
-In order to support Typescript, you need to enable `preprocess`.
-
-1. Update your jest configuration
-
- ```json
- {
- "jest": {
- "transform": {
- "^.+\\.svelte$": ["svelte-jester", { "preprocess": true }]
- },
- "moduleFileExtensions": ["js", "ts", "svelte"]
- }
- }
- ```
+To use Typescript, you'll need to install and configure `svelte-preprocess` and
+`ts-jest`. For full instructions, see the
+[`svelte-jester` docs](https://github.com/mihar-22/svelte-jester#typescript)
+docs.
## Babel / Preprocessors
From faa4b6fa85f5ae35d49e75b386cd03afa1cc5681 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Mon, 3 Aug 2020 11:56:50 +0000
Subject: [PATCH 191/903] docs: update README.md [skip ci]
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 9ecdfb0ab..3874f3766 100644
--- a/README.md
+++ b/README.md
@@ -154,6 +154,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Batuhan Wilhelm π
Dennis Kaffer π
+ Cam Jackson π
From ef7d125b9f805677901edc8b4c0bf85118dfc271 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Mon, 3 Aug 2020 11:56:51 +0000
Subject: [PATCH 192/903] docs: update .all-contributorsrc [skip ci]
---
.all-contributorsrc | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 398821f4f..57237f923 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -846,6 +846,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "camjackson",
+ "name": "Cam Jackson",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/1930451?v=4",
+ "profile": "http://camjackson.net/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
From f3ccf22941afa740ee7645e8c1a92335998f7fe5 Mon Sep 17 00:00:00 2001
From: Rahim Alwer
Date: Mon, 3 Aug 2020 22:08:33 +1000
Subject: [PATCH 193/903] docs(svelte): typo in typescript instructions
---
docs/svelte-testing-library/setup.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/svelte-testing-library/setup.md b/docs/svelte-testing-library/setup.md
index c434db92e..60cb95f76 100644
--- a/docs/svelte-testing-library/setup.md
+++ b/docs/svelte-testing-library/setup.md
@@ -76,7 +76,7 @@ with any testing framework and runner you're comfortable with.
To use Typescript, you'll need to install and configure `svelte-preprocess` and
`ts-jest`. For full instructions, see the
-[`svelte-jester` docs](https://github.com/mihar-22/svelte-jester#typescript)
+[`svelte-jester`](https://github.com/mihar-22/svelte-jester#typescript)
docs.
## Babel / Preprocessors
From d96d980440c99650e97dfb89695795c34be8ef8a Mon Sep 17 00:00:00 2001
From: Tolunay Akbulut <31761883+tolunayakbulut@users.noreply.github.com>
Date: Tue, 4 Aug 2020 19:32:09 +0300
Subject: [PATCH 194/903] Added Global CTO Forum to users. Thanks for
developing testing-library (#549)
Co-authored-by: John Doe
---
website/siteConfig.js | 6 ++
website/static/img/users/global-cto-forum.svg | 57 +++++++++++++++++++
2 files changed, 63 insertions(+)
create mode 100644 website/static/img/users/global-cto-forum.svg
diff --git a/website/siteConfig.js b/website/siteConfig.js
index 93d5d32e4..004c53cf4 100755
--- a/website/siteConfig.js
+++ b/website/siteConfig.js
@@ -106,6 +106,12 @@ const users = [
infoLink: 'https://radity.com/',
pinned: true,
},
+ {
+ caption: 'Global CTO Forum',
+ image: '/img/users/global-cto-forum.svg',
+ infoLink: 'https://globalctoforum.org/',
+ pinned: true,
+ },
{
caption: 'Gusto',
image: '/img/users/gusto.svg',
diff --git a/website/static/img/users/global-cto-forum.svg b/website/static/img/users/global-cto-forum.svg
new file mode 100644
index 000000000..55c5026d6
--- /dev/null
+++ b/website/static/img/users/global-cto-forum.svg
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From bddfacc16493a84466e4bdf50b06b0983ef91df3 Mon Sep 17 00:00:00 2001
From: Jared Luxenberg
Date: Thu, 6 Aug 2020 12:33:07 -0700
Subject: [PATCH 195/903] docs(ByRole): Add `{ pressed: boolean }` option for
querying by aria-pressed state (#551)
---
docs/dom-testing-library/api-queries.md | 34 ++++++++++++++++++++++---
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index dc9bf1e1a..276a1b3db 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -617,6 +617,7 @@ getByRole(
normalizer?: NormalizerFn,
selected?: boolean,
checked?: boolean,
+ pressed?: boolean,
queryFallbacks?: boolean,
}): HTMLElement
```
@@ -677,8 +678,10 @@ assertions about the `Open dialog`-button you would need to use
The default value for `hidden` can
[be configured](api-configuration#configuration).
-Certain roles can have a selected state. You can filter the returned elements by
-their selected state by setting `selected: true` or `selected: false`.
+#### `selected`
+
+You can filter the returned elements by their selected state by setting
+`selected: true` or `selected: false`.
For example in
@@ -696,8 +699,10 @@ you can get the "Native"-tab by calling `getByRole('tab', { selected: true })`.
To learn more about the selected state and which elements can have this state
see [ARIA `aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected).
-Certain roles can have a checked state. You can filter the returned elements by
-their checked state by setting `checked: true` or `checked: false`.
+#### `checked`
+
+You can filter the returned elements by their checked state by setting
+`checked: true` or `checked: false`.
For example in
@@ -720,6 +725,27 @@ state and which elements can have this state see
> nor unchecked (details
> [here](https://www.w3.org/TR/html-aam-1.0/#details-id-56)).
+#### `pressed`
+
+Buttons can have a pressed state. You can filter the returned elements by
+their pressed state by setting `pressed: true` or `pressed: false`.
+
+For example in
+
+```html
+
+
+
+```
+
+you can get the "π" button by calling
+`getByRole('button', { pressed: true })`. To learn more about the pressed
+state see
+[ARIA `aria-pressed`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed).
+
```html
...
```
From c821f00bdcab289e37c4a3fab93e3e4d395d4b6a Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Thu, 6 Aug 2020 13:35:14 -0600
Subject: [PATCH 196/903] docs: add jluxenberg as a contributor (#552)
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 57237f923..3a07401ea 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -855,6 +855,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "jluxenberg",
+ "name": "Jared Luxenberg",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/450478?v=4",
+ "profile": "http://www.jaredlux.com/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 3874f3766..3f667707e 100644
--- a/README.md
+++ b/README.md
@@ -155,6 +155,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Batuhan Wilhelm π
Dennis Kaffer π
Cam Jackson π
+ Jared Luxenberg π
From 58651e830db7d883f561fb8c3eeed13e672fd000 Mon Sep 17 00:00:00 2001
From: Yakir Narkis
Date: Fri, 7 Aug 2020 00:31:31 +0300
Subject: [PATCH 197/903] Fix use of wait in docs (#550)
Example is importing `wait` but calling `waitFor`
---
docs/pptr-testing-library/intro.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/pptr-testing-library/intro.md b/docs/pptr-testing-library/intro.md
index 8c41ee63d..b3956eedb 100644
--- a/docs/pptr-testing-library/intro.md
+++ b/docs/pptr-testing-library/intro.md
@@ -32,7 +32,7 @@ const $email = await getByLabelText($form, 'Email')
// interact with puppeteer like usual
await $email.type('pptr@example.com')
// waiting works too!
-await waitFor(() => getByText('Loading...'))
+await wait(() => getByText('Loading...'))
```
A little too un-puppeteer for you? You can attach all the `DOM Testing Library`
From 72bd0952d14fcf5461d03cc207a26249b2f76364 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Thu, 6 Aug 2020 15:33:54 -0600
Subject: [PATCH 198/903] docs: add yakirn as a contributor (#553)
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 3a07401ea..60e94a74d 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -864,6 +864,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "yakirn",
+ "name": "Yakir Narkis",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/6659632?v=4",
+ "profile": "https://github.com/yakirn",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 3f667707e..eeffea182 100644
--- a/README.md
+++ b/README.md
@@ -156,6 +156,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Dennis Kaffer π
Cam Jackson π
Jared Luxenberg π
+ Yakir Narkis π
From 91036136864c4d17b96c47fa8017349d27f5409a Mon Sep 17 00:00:00 2001
From: Rahul Bhooteshwar
Date: Fri, 7 Aug 2020 22:06:55 +0530
Subject: [PATCH 199/903] docs(intro): note for create-react-app OOTB support
(#554)
Co-authored-by: Kent C. Dodds
---
docs/react-testing-library/intro.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/docs/react-testing-library/intro.md b/docs/react-testing-library/intro.md
index 4070b7c3b..353645d94 100644
--- a/docs/react-testing-library/intro.md
+++ b/docs/react-testing-library/intro.md
@@ -7,6 +7,10 @@ sidebar_label: Introduction
[`React Testing Library`][gh] builds on top of `DOM Testing Library` by adding
APIs for working with React components.
+> Projects created with [`Create React App`](https://create-react-app.dev/) have
+> out of the box support for **React Testing Library**. If that is not the case,
+> you can add it via `npm` like so:
+
```
npm install --save-dev @testing-library/react
```
From dcf308c34f33e5564096419b7b25ad0bba8f7249 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Fri, 7 Aug 2020 10:38:44 -0600
Subject: [PATCH 200/903] docs: add rahulbhooteshwar as a contributor (#555)
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 60e94a74d..c9ebf3339 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -873,6 +873,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "rahulbhooteshwar",
+ "name": "Rahul Bhooteshwar",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/15920476?v=4",
+ "profile": "https://rahulbhooteshwar.github.io/",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index eeffea182..65d67a063 100644
--- a/README.md
+++ b/README.md
@@ -157,6 +157,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Cam Jackson π
Jared Luxenberg π
Yakir Narkis π
+ Rahul Bhooteshwar π
From c945833c0fc0ddfa4d9ef5751c50fbe2bffbff36 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Fri, 7 Aug 2020 12:58:55 -0600
Subject: [PATCH 201/903] replace wait with waitFor for puppeteer (#557)
---
docs/pptr-testing-library/intro.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/pptr-testing-library/intro.md b/docs/pptr-testing-library/intro.md
index b3956eedb..ac52bfdb8 100644
--- a/docs/pptr-testing-library/intro.md
+++ b/docs/pptr-testing-library/intro.md
@@ -16,7 +16,7 @@ npm install --save-dev puppeteer pptr-testing-library
```js
const puppeteer = require('puppeteer')
-const { getDocument, queries, wait } = require('pptr-testing-library')
+const { getDocument, queries, waitFor } = require('pptr-testing-library')
const { getByTestId, getByLabelText } = queries
@@ -32,7 +32,7 @@ const $email = await getByLabelText($form, 'Email')
// interact with puppeteer like usual
await $email.type('pptr@example.com')
// waiting works too!
-await wait(() => getByText('Loading...'))
+await waitFor(() => getByText('Loading...'))
```
A little too un-puppeteer for you? You can attach all the `DOM Testing Library`
From 59610a4db98c210a6b6458adc380eec1496cafcb Mon Sep 17 00:00:00 2001
From: Maja Wichrowska
Date: Fri, 7 Aug 2020 12:42:48 -0700
Subject: [PATCH 202/903] Add `timeout` to configuration docs (#556)
According to the release notes for `dom-testing-library@7` (https://github.com/testing-library/dom-testing-library/releases/tag/v7.0.0), this is configurable at the global level.
I also wanted to fix the docusaurus code tabs because they don't seem to register new lines (which is confusing), but... that seems to also be a problem in the docusaurus documentation itself: https://docusaurus.io/docs/en/doc-markdown#language-specific-code-tabs Don't know if anyone has any ideas on that.
---
docs/dom-testing-library/api-configuration.md | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/docs/dom-testing-library/api-configuration.md b/docs/dom-testing-library/api-configuration.md
index 3fafb6f6f..6f3641235 100644
--- a/docs/dom-testing-library/api-configuration.md
+++ b/docs/dom-testing-library/api-configuration.md
@@ -44,6 +44,13 @@ and related queries. Defaults to `data-testid`.
[`getBy*`](api-queries#getby) or [`getAllBy*`](api-queries#getallby) fail. Takes
the error message and container object as arguments.
+`getElementError`: A function that returns the error used when
+[`getBy*`](api-queries#getby) or [`getAllBy*`](api-queries#getallby) fail. Takes
+the error message and container object as arguments.
+
+`timeout`: The global timeout value in milliseconds used by `waitFor` utilities.
+Defaults to 1000ms.
+
From dbd4a50229fdb65383f59785a04650b2bbf0394d Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Fri, 7 Aug 2020 13:45:00 -0600
Subject: [PATCH 203/903] docs: add majapw as a contributor (#558)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index c9ebf3339..cc76df657 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -882,6 +882,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "majapw",
+ "name": "Maja Wichrowska",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/1383861?v=4",
+ "profile": "https://github.com/majapw",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 65d67a063..3de3fefba 100644
--- a/README.md
+++ b/README.md
@@ -158,6 +158,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Jared Luxenberg π
Yakir Narkis π
Rahul Bhooteshwar π
+ Maja Wichrowska π
From 70b1b04346c2d81999158cad0e1f86495de974fd Mon Sep 17 00:00:00 2001
From: Rahul Bhooteshwar
Date: Sun, 9 Aug 2020 08:07:38 +0530
Subject: [PATCH 204/903] fix(docs): correct typo in full example (#559)
---
docs/react-testing-library/example-intro.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/react-testing-library/example-intro.md b/docs/react-testing-library/example-intro.md
index 0ea0bd15e..6b5e37bf2 100644
--- a/docs/react-testing-library/example-intro.md
+++ b/docs/react-testing-library/example-intro.md
@@ -38,7 +38,7 @@ test('loads and displays greeting', async () => {
expect(screen.getByRole('button')).toHaveAttribute('disabled')
})
-test('handlers server error', async () => {
+test('handles server error', async () => {
server.use(
rest.get('/greeting', (req, res, ctx) => {
return res(ctx.status(500))
From d6d013c2665ab5a317e621e9e3c7b415898b8d74 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sat, 8 Aug 2020 20:38:13 -0600
Subject: [PATCH 205/903] docs: add rahulbhooteshwar as a contributor (#560)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
From 12e486a104b7385d9be76b76fc045be37110e1f1 Mon Sep 17 00:00:00 2001
From: Kermani <98kermani@gmail.com>
Date: Sun, 9 Aug 2020 18:24:28 +0430
Subject: [PATCH 206/903] Update the documentation to resolve confusion around
AREA semantic and getByRole (#562)
See #561
---
docs/dom-testing-library/api-queries.md | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index 276a1b3db..abac3c249 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -625,12 +625,10 @@ getByRole(
Queries for elements with the given role (and it also accepts a
[`TextMatch`](#textmatch)). Default roles are taken into consideration e.g.
` ` has the `button` role without explicitly setting the `role`
-attribute. The
-[W3C HTML recommendation](https://www.w3.org/TR/html5/index.html#contents) lists
-all HTML elements with their default ARIA roles. Additionally, as DOM Testing
-Library uses `aria-query` under the hood to find those elements by their default
-ARIA roles, you can find in their docs
-[which HTML Elements with inherent roles are mapped to each role](https://github.com/A11yance/aria-query#elements-to-roles).
+attribute. Here you can see
+[a table of HTML elements with their default and desired roles](https://www.w3.org/TR/html-aria/#docconformance).
+
+Please note that setting a `role` and/or `aria-*` attribute that matches the implicit ARIA semantics is unnecessary and is **not recomended** as these properties are already set by the browser, and we must not use the `role` and `aria-*` attributes in a manner that conflicts with the semantics described. For example, a `button` element can't have the `role` attribute of `heading`, because the `button` element has default characteristics that conflict with the `heading` role.
> Roles are matched literally by string equality, without inheriting from the
> ARIA role hierarchy. As a result, querying a superclass role like `checkbox`
From 4cffaeaf61323bfe5322bcf67cee95441e04dd1c Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 9 Aug 2020 07:54:57 -0600
Subject: [PATCH 207/903] docs: add m98 as a contributor (#564)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 3 +++
2 files changed, 12 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index cc76df657..ad62d1709 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -891,6 +891,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "m98",
+ "name": "Kermani",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/7496103?v=4",
+ "profile": "http://medium.com/@kermani",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 3de3fefba..fdf3c7f23 100644
--- a/README.md
+++ b/README.md
@@ -160,6 +160,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Rahul Bhooteshwar π
Maja Wichrowska π
+
+ Kermani π
+
From 703f2982193f4fda3868cdb9f2b277d3a864c42d Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Mon, 10 Aug 2020 15:50:33 -0600
Subject: [PATCH 208/903] Update api-events.md
---
docs/dom-testing-library/api-events.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/docs/dom-testing-library/api-events.md b/docs/dom-testing-library/api-events.md
index 1a7bdf6ee..53e758799 100644
--- a/docs/dom-testing-library/api-events.md
+++ b/docs/dom-testing-library/api-events.md
@@ -3,6 +3,9 @@ id: api-events
title: Firing Events
---
+> Most projects have a few use cases for `fireEvent`, but the majority of the time you should
+> probably use [`@testing-library/user-event`](https://github.com/testing-library/user-event).
+
## `fireEvent`
```typescript
From 9b6efc6e28ca2e76ae796af6d94e4fc2082a1483 Mon Sep 17 00:00:00 2001
From: Sebastian Silbermann
Date: Tue, 11 Aug 2020 00:26:34 +0200
Subject: [PATCH 209/903] Document `computedStyleSupportsPseudoElements` config
(#565)
---
docs/dom-testing-library/api-configuration.md | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/docs/dom-testing-library/api-configuration.md b/docs/dom-testing-library/api-configuration.md
index 6f3641235..b5c8f5851 100644
--- a/docs/dom-testing-library/api-configuration.md
+++ b/docs/dom-testing-library/api-configuration.md
@@ -15,6 +15,16 @@ The library can be configured via the `configure` function, which accepts:
Configuration options:
+`computedStyleSupportsPseudoElements`: Set to `true` if
+`window.getComputedStyle` supports pseudo-elements i.e. a second argument. If
+you're using testing-library in a browser you almost always want to set this to
+`true`. Only very old browser don't support his property (such as IE 8 and
+earlier). However, `jsdom` does not support the second argument currently. This
+includes versions of `jsdom` prior to `16.4.0` and any version that logs a
+`not implemented` warning when calling `getComputedStyle` with a second argument
+e.g. `window.getComputedStyle(document.createElement('div'), '::after')`.
+Defaults to `false`
+
`defaultHidden`: The default value for the `hidden` option used by
[`getByRole`](api-queries#byrole). Defaults to `false`.
From 473abdce2b019fca3bd9772bbefe19a2df786e78 Mon Sep 17 00:00:00 2001
From: Sherman Hui
Date: Wed, 19 Aug 2020 16:34:18 -0700
Subject: [PATCH 210/903] docs: fix `api-queries.md` minor grammar typos and
"Note" block styles (#567)
---
docs/dom-testing-library/api-configuration.md | 4 +-
docs/dom-testing-library/api-events.md | 5 +-
docs/dom-testing-library/api-queries.md | 46 ++++++++++++-------
docs/svelte-testing-library/setup.md | 3 +-
4 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/docs/dom-testing-library/api-configuration.md b/docs/dom-testing-library/api-configuration.md
index b5c8f5851..4ec7940e8 100644
--- a/docs/dom-testing-library/api-configuration.md
+++ b/docs/dom-testing-library/api-configuration.md
@@ -58,8 +58,8 @@ the error message and container object as arguments.
[`getBy*`](api-queries#getby) or [`getAllBy*`](api-queries#getallby) fail. Takes
the error message and container object as arguments.
-`timeout`: The global timeout value in milliseconds used by `waitFor` utilities.
-Defaults to 1000ms.
+`timeout`: The global timeout value in milliseconds used by `waitFor` utilities.
+Defaults to 1000ms.
diff --git a/docs/dom-testing-library/api-events.md b/docs/dom-testing-library/api-events.md
index 53e758799..b75c20401 100644
--- a/docs/dom-testing-library/api-events.md
+++ b/docs/dom-testing-library/api-events.md
@@ -3,8 +3,9 @@ id: api-events
title: Firing Events
---
-> Most projects have a few use cases for `fireEvent`, but the majority of the time you should
-> probably use [`@testing-library/user-event`](https://github.com/testing-library/user-event).
+> Most projects have a few use cases for `fireEvent`, but the majority of the
+> time you should probably use
+> [`@testing-library/user-event`](https://github.com/testing-library/user-event).
## `fireEvent`
diff --git a/docs/dom-testing-library/api-queries.md b/docs/dom-testing-library/api-queries.md
index abac3c249..aeae82341 100644
--- a/docs/dom-testing-library/api-queries.md
+++ b/docs/dom-testing-library/api-queries.md
@@ -37,7 +37,9 @@ matches the given query. The promise is rejected if no element is found or if
more than one element is found after a default timeout of `1000`ms. If you need
to find more than one element, then use `findAllBy`.
-> Note, this is a simple combination of `getBy*` queries and
+> **Note**
+>
+> this is a simple combination of `getBy*` queries and
> [`waitFor`](/docs/api-async#waitfor). The `findBy*` queries accept the
> `waitFor` options as the last argument. (i.e.
> `screen.findByText('text', queryOptions, waitForOptions)`)
@@ -106,7 +108,9 @@ screen.debug(screen.getAllByText('multi-test'))
## Queries
-> NOTE: These queries are the base queries and require you pass a `container` as
+> **Note**
+>
+> These queries are the base queries and require you to pass a `container` as
> the first argument. Most framework-implementations of Testing Library provide
> a pre-bound version of these queries when you render your components with them
> which means you do not have to provide a container. In addition, if you just
@@ -220,8 +224,10 @@ If it is important that you query an actual `` element you can provide a
const inputNode = screen.getByLabelText('Username', { selector: 'input' })
```
-Note that it will not work in the case where a `for` attr on a `label` matches
-and `id` field on a non-form element.
+> **Note**
+>
+> `getByLabelText` will not work in the case where a `for` attribute on a
+> `` element matches an `id` attribute on a non-form element.
```js
// This case is not valid
@@ -628,7 +634,13 @@ Queries for elements with the given role (and it also accepts a
attribute. Here you can see
[a table of HTML elements with their default and desired roles](https://www.w3.org/TR/html-aria/#docconformance).
-Please note that setting a `role` and/or `aria-*` attribute that matches the implicit ARIA semantics is unnecessary and is **not recomended** as these properties are already set by the browser, and we must not use the `role` and `aria-*` attributes in a manner that conflicts with the semantics described. For example, a `button` element can't have the `role` attribute of `heading`, because the `button` element has default characteristics that conflict with the `heading` role.
+Please note that setting a `role` and/or `aria-*` attribute that matches the
+implicit ARIA semantics is unnecessary and is **not recomended** as these
+properties are already set by the browser, and we must not use the `role` and
+`aria-*` attributes in a manner that conflicts with the semantics described. For
+example, a `button` element can't have the `role` attribute of `heading`,
+because the `button` element has default characteristics that conflict with the
+`heading` role.
> Roles are matched literally by string equality, without inheriting from the
> ARIA role hierarchy. As a result, querying a superclass role like `checkbox`
@@ -719,14 +731,15 @@ you can get the "Sugar" option by calling
state and which elements can have this state see
[ARIA `aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked).
-> **Note:** Checkboxes have a "mixed" state, which is considered neither checked
-> nor unchecked (details
-> [here](https://www.w3.org/TR/html-aam-1.0/#details-id-56)).
+> **Note**
+>
+> Checkboxes have a "mixed" state, which is considered neither checked nor
+> unchecked (details [here](https://www.w3.org/TR/html-aam-1.0/#details-id-56)).
#### `pressed`
-Buttons can have a pressed state. You can filter the returned elements by
-their pressed state by setting `pressed: true` or `pressed: false`.
+Buttons can have a pressed state. You can filter the returned elements by their
+pressed state by setting `pressed: true` or `pressed: false`.
For example in
@@ -739,9 +752,8 @@ For example in