diff --git a/.all-contributorsrc b/.all-contributorsrc
index f7e9353d..431ed13e 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -615,6 +615,18 @@
"contributions": [
"code"
]
+ },
+ {
+ "login": "donavon",
+ "name": "Donavon West",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/887639?v=4",
+ "profile": "http://donavon.com",
+ "contributions": [
+ "code",
+ "doc",
+ "ideas",
+ "test"
+ ]
}
]
}
diff --git a/README.md b/README.md
index 7d47c49e..ade2fa8b 100644
--- a/README.md
+++ b/README.md
@@ -7,11 +7,11 @@
Simple and complete React DOM testing utilities that encourage good testing practices.
-[**Read The Docs**](https://testing-library.com/react) | [Edit the docs](https://github.com/alexkrolick/testing-library-docs)
+[**Read The Docs**](https://testing-library.com/react) |
+[Edit the docs](https://github.com/alexkrolick/testing-library-docs)
-
@@ -20,7 +20,7 @@
[![version][version-badge]][package] [![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]
-[](#contributors)
+[](#contributors)
[![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc]
[![Join the community on Spectrum][spectrum-badge]][spectrum]
@@ -40,8 +40,8 @@
-- [The Problem](#the-problem)
-- [This Solution](#this-solution)
+- [The problem](#the-problem)
+- [This solution](#this-solution)
- [Example](#example)
- [Installation](#installation)
- [Examples](#examples)
@@ -76,7 +76,6 @@ primary guiding principle is:
> [The more your tests resemble the way your software is used, the more
> confidence they can give you.][guiding-principle]
-
## Example
```javascript
@@ -134,14 +133,13 @@ should be installed as one of your project's `devDependencies`:
npm install --save-dev react-testing-library
```
-This library has a `peerDependencies` listing for `react-dom`.
+This library has `peerDependencies` listings for `react` and `react-dom`.
You may also be interested in installing `jest-dom` so you can use
[the custom jest matchers](https://github.com/gnapse/jest-dom#readme).
> [**Docs**](https://testing-library.com/docs/react-testing-library/intro)
-
## Examples
> We're in the process of moving examples to the
@@ -154,6 +152,8 @@ Some included are:
- [`react-redux`](https://github.com/kentcdodds/react-testing-library/blob/master/examples/__tests__/react-redux.js)
- [`react-router`](https://github.com/kentcdodds/react-testing-library/blob/master/examples/__tests__/react-router.js)
- [`react-context`](https://github.com/kentcdodds/react-testing-library/blob/master/examples/__tests__/react-context.js)
+- [`react-hooks`](https://github.com/kentcdodds/react-testing-library/blob/master/examples/__tests__/react-hooks.js) -
+ Use react-testing-library to test a custom React Hook.
You can also find react-testing-library examples at
[react-testing-examples.com](https://react-testing-examples.com/jest-rtl/).
@@ -196,16 +196,17 @@ Thanks goes to these people ([emoji key][emojis]):
-| [
Kent C. Dodds](https://kentcdodds.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Documentation") [π](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Tests") | [
Ryan Castner](http://audiolion.github.io)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=audiolion "Documentation") | [
Daniel Sandiego](https://www.dnlsandiego.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=dnlsandiego "Code") | [
PaweΕ MikoΕajczyk](https://github.com/Miklet)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=Miklet "Code") | [
Alejandro ΓÑñez Ortiz](http://co.linkedin.com/in/alejandronanez/)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=alejandronanez "Documentation") | [
Matt Parrish](https://github.com/pbomb)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Apbomb "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=pbomb "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=pbomb "Documentation") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=pbomb "Tests") | [
Justin Hall](https://github.com/wKovacs64)
[π¦](#platform-wKovacs64 "Packaging/porting to new platform") |
+| [
Kent C. Dodds](https://kentcdodds.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Documentation") [π](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=kentcdodds "Tests") | [
Ryan Castner](http://audiolion.github.io)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=audiolion "Documentation") | [
Daniel Sandiego](https://www.dnlsandiego.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=dnlsandiego "Code") | [
PaweΕ MikoΕajczyk](https://github.com/Miklet)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=Miklet "Code") | [
Alejandro ΓÑñez Ortiz](http://co.linkedin.com/in/alejandronanez/)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=alejandronanez "Documentation") | [
Matt Parrish](https://github.com/pbomb)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Apbomb "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=pbomb "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=pbomb "Documentation") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=pbomb "Tests") | [
Justin Hall](https://github.com/wKovacs64)
[π¦](#platform-wKovacs64 "Packaging/porting to new platform") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
-| [
Anto Aravinth](https://github.com/antoaravinth)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=antoaravinth "Code") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=antoaravinth "Tests") [π](https://github.com/kentcdodds/react-testing-library/commits?author=antoaravinth "Documentation") | [
Jonah Moses](https://github.com/JonahMoses)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=JonahMoses "Documentation") | [
Εukasz Gandecki](http://team.thebrain.pro)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=lgandecki "Code") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=lgandecki "Tests") [π](https://github.com/kentcdodds/react-testing-library/commits?author=lgandecki "Documentation") | [
Ivan Babak](https://sompylasar.github.io)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Asompylasar "Bug reports") [π€](#ideas-sompylasar "Ideas, Planning, & Feedback") | [
Jesse Day](https://github.com/jday3)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=jday3 "Code") | [
Ernesto GarcΓa](http://gnapse.github.io)
[π¬](#question-gnapse "Answering Questions") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=gnapse "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=gnapse "Documentation") | [
Josef Maxx Blake](http://jomaxx.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=jomaxx "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=jomaxx "Documentation") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=jomaxx "Tests") |
-| [
Michal Baranowski](https://twitter.com/baranovskim)
[π](#blog-mbaranovski "Blogposts") [β
](#tutorial-mbaranovski "Tutorials") | [
Arthur Puthin](https://github.com/aputhin)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=aputhin "Documentation") | [
Thomas Chia](https://github.com/thchia)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=thchia "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=thchia "Documentation") | [
Thiago Galvani](http://ilegra.com/)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=thiagopaiva99 "Documentation") | [
Christian](http://Chriswcs.github.io)
[β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=ChrisWcs "Tests") | [
Alex Krolick](https://alexkrolick.com)
[π¬](#question-alexkrolick "Answering Questions") [π](https://github.com/kentcdodds/react-testing-library/commits?author=alexkrolick "Documentation") [π‘](#example-alexkrolick "Examples") [π€](#ideas-alexkrolick "Ideas, Planning, & Feedback") | [
Johann Hubert Sonntagbauer](https://github.com/johann-sonntagbauer)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=johann-sonntagbauer "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=johann-sonntagbauer "Documentation") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=johann-sonntagbauer "Tests") |
-| [
Maddi Joyce](http://www.maddijoyce.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=maddijoyce "Code") | [
Ryan Vice](http://www.vicesoftware.com)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=RyanAtViceSoftware "Documentation") | [
Ian Wilson](https://ianwilson.io)
[π](#blog-iwilsonq "Blogposts") [β
](#tutorial-iwilsonq "Tutorials") | [
Daniel](https://github.com/InExtremaRes)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3AInExtremaRes "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=InExtremaRes "Code") | [
Giorgio Polvara](https://twitter.com/Gpx)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3AGpx "Bug reports") [π€](#ideas-Gpx "Ideas, Planning, & Feedback") | [
John Gozde](https://github.com/jgoz)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=jgoz "Code") | [
Sam Horton](https://twitter.com/SavePointSam)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=SavePointSam "Documentation") [π‘](#example-SavePointSam "Examples") [π€](#ideas-SavePointSam "Ideas, Planning, & Feedback") |
-| [
Richard Kotze (mobile)](http://www.richardkotze.com)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=rkotze "Documentation") | [
Brahian E. Soto Mercedes](https://github.com/sotobuild)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=sotobuild "Documentation") | [
Benoit de La Forest](https://github.com/bdelaforest)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=bdelaforest "Documentation") | [
Salah](https://github.com/thesalah)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=thesalah "Code") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=thesalah "Tests") | [
Adam Gordon](http://gordonizer.com)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Aicfantv "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=icfantv "Code") | [
Matija MarohniΔ](https://silvenon.com)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=silvenon "Documentation") | [
Justice Mba](https://github.com/Dajust)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=Dajust "Documentation") |
-| [
Mark Pollmann](https://markpollmann.com/)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=MarkPollmann "Documentation") | [
Ehtesham Kafeel](https://github.com/ehteshamkafeel)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=ehteshamkafeel "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=ehteshamkafeel "Documentation") | [
Julio PavΓ³n](http://jpavon.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=jpavon "Code") | [
Duncan L](http://www.duncanleung.com/)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=duncanleung "Documentation") [π‘](#example-duncanleung "Examples") | [
Tiago Almeida](https://www.linkedin.com/in/tyagow/?locale=en_US)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=tyagow "Documentation") | [
Robert Smith](http://rbrtsmith.com/)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Arbrtsmith "Bug reports") | [
Zach Green](https://offbyone.tech)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=zgreen "Documentation") |
-| [
dadamssg](https://github.com/dadamssg)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=dadamssg "Documentation") | [
Yazan Aabed](https://www.yaabed.com/)
[π](#blog-YazanAabeed "Blogposts") | [
Tim](https://github.com/timbonicus)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Atimbonicus "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Documentation") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Tests") | [
Divyanshu Maithani](http://divyanshu.xyz)
[β
](#tutorial-divyanshu013 "Tutorials") [πΉ](#video-divyanshu013 "Videos") | [
Deepak Grover](https://www.linkedin.com/in/metagrover)
[β
](#tutorial-metagrover "Tutorials") [πΉ](#video-metagrover "Videos") | [
Eyal Cohen](https://github.com/eyalcohen4)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=eyalcohen4 "Documentation") | [
Peter Makowski](https://github.com/petermakowski)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=petermakowski "Documentation") |
-| [
Michiel Nuyts](https://github.com/Michielnuyts)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=Michielnuyts "Documentation") | [
Joe Ng'ethe](https://github.com/joeynimu)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=joeynimu "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=joeynimu "Documentation") | [
Kate](https://github.com/Enikol)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=Enikol "Documentation") | [
Sean](http://www.seanrparker.com)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=SeanRParker "Documentation") | [
James Long](http://jlongster.com)
[π€](#ideas-jlongster "Ideas, Planning, & Feedback") [π¦](#platform-jlongster "Packaging/porting to new platform") | [
Herb Hagely](https://github.com/hhagely)
[π‘](#example-hhagely "Examples") | [
Alex Wendte](http://www.wendtedesigns.com/)
[π‘](#example-themostcolm "Examples") |
-| [
Monica Powell](http://www.aboutmonica.com)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=M0nica "Documentation") | [
Vitaly Sivkov](http://sivkoff.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=sivkoff "Code") | [
Weyert de Boer](https://github.com/weyert)
[π€](#ideas-weyert "Ideas, Planning, & Feedback") [π](#review-weyert "Reviewed Pull Requests") | [
EstebanMarin](https://github.com/EstebanMarin)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=EstebanMarin "Documentation") | [
Victor Martins](https://github.com/vctormb)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=vctormb "Documentation") | [
Royston Shufflebotham](https://github.com/RoystonS)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3ARoystonS "Bug reports") [π](https://github.com/kentcdodds/react-testing-library/commits?author=RoystonS "Documentation") [π‘](#example-RoystonS "Examples") | [
chrbala](https://github.com/chrbala)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=chrbala "Code") |
+| [
Anto Aravinth](https://github.com/antoaravinth)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=antoaravinth "Code") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=antoaravinth "Tests") [π](https://github.com/kentcdodds/react-testing-library/commits?author=antoaravinth "Documentation") | [
Jonah Moses](https://github.com/JonahMoses)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=JonahMoses "Documentation") | [
Εukasz Gandecki](http://team.thebrain.pro)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=lgandecki "Code") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=lgandecki "Tests") [π](https://github.com/kentcdodds/react-testing-library/commits?author=lgandecki "Documentation") | [
Ivan Babak](https://sompylasar.github.io)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Asompylasar "Bug reports") [π€](#ideas-sompylasar "Ideas, Planning, & Feedback") | [
Jesse Day](https://github.com/jday3)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=jday3 "Code") | [
Ernesto GarcΓa](http://gnapse.github.io)
[π¬](#question-gnapse "Answering Questions") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=gnapse "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=gnapse "Documentation") | [
Josef Maxx Blake](http://jomaxx.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=jomaxx "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=jomaxx "Documentation") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=jomaxx "Tests") |
+| [
Michal Baranowski](https://twitter.com/baranovskim)
[π](#blog-mbaranovski "Blogposts") [β
](#tutorial-mbaranovski "Tutorials") | [
Arthur Puthin](https://github.com/aputhin)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=aputhin "Documentation") | [
Thomas Chia](https://github.com/thchia)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=thchia "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=thchia "Documentation") | [
Thiago Galvani](http://ilegra.com/)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=thiagopaiva99 "Documentation") | [
Christian](http://Chriswcs.github.io)
[β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=ChrisWcs "Tests") | [
Alex Krolick](https://alexkrolick.com)
[π¬](#question-alexkrolick "Answering Questions") [π](https://github.com/kentcdodds/react-testing-library/commits?author=alexkrolick "Documentation") [π‘](#example-alexkrolick "Examples") [π€](#ideas-alexkrolick "Ideas, Planning, & Feedback") | [
Johann Hubert Sonntagbauer](https://github.com/johann-sonntagbauer)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=johann-sonntagbauer "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=johann-sonntagbauer "Documentation") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=johann-sonntagbauer "Tests") |
+| [
Maddi Joyce](http://www.maddijoyce.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=maddijoyce "Code") | [
Ryan Vice](http://www.vicesoftware.com)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=RyanAtViceSoftware "Documentation") | [
Ian Wilson](https://ianwilson.io)
[π](#blog-iwilsonq "Blogposts") [β
](#tutorial-iwilsonq "Tutorials") | [
Daniel](https://github.com/InExtremaRes)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3AInExtremaRes "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=InExtremaRes "Code") | [
Giorgio Polvara](https://twitter.com/Gpx)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3AGpx "Bug reports") [π€](#ideas-Gpx "Ideas, Planning, & Feedback") | [
John Gozde](https://github.com/jgoz)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=jgoz "Code") | [
Sam Horton](https://twitter.com/SavePointSam)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=SavePointSam "Documentation") [π‘](#example-SavePointSam "Examples") [π€](#ideas-SavePointSam "Ideas, Planning, & Feedback") |
+| [
Richard Kotze (mobile)](http://www.richardkotze.com)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=rkotze "Documentation") | [
Brahian E. Soto Mercedes](https://github.com/sotobuild)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=sotobuild "Documentation") | [
Benoit de La Forest](https://github.com/bdelaforest)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=bdelaforest "Documentation") | [
Salah](https://github.com/thesalah)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=thesalah "Code") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=thesalah "Tests") | [
Adam Gordon](http://gordonizer.com)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Aicfantv "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=icfantv "Code") | [
Matija MarohniΔ](https://silvenon.com)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=silvenon "Documentation") | [
Justice Mba](https://github.com/Dajust)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=Dajust "Documentation") |
+| [
Mark Pollmann](https://markpollmann.com/)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=MarkPollmann "Documentation") | [
Ehtesham Kafeel](https://github.com/ehteshamkafeel)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=ehteshamkafeel "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=ehteshamkafeel "Documentation") | [
Julio PavΓ³n](http://jpavon.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=jpavon "Code") | [
Duncan L](http://www.duncanleung.com/)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=duncanleung "Documentation") [π‘](#example-duncanleung "Examples") | [
Tiago Almeida](https://www.linkedin.com/in/tyagow/?locale=en_US)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=tyagow "Documentation") | [
Robert Smith](http://rbrtsmith.com/)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Arbrtsmith "Bug reports") | [
Zach Green](https://offbyone.tech)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=zgreen "Documentation") |
+| [
dadamssg](https://github.com/dadamssg)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=dadamssg "Documentation") | [
Yazan Aabed](https://www.yaabed.com/)
[π](#blog-YazanAabeed "Blogposts") | [
Tim](https://github.com/timbonicus)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Atimbonicus "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Documentation") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Tests") | [
Divyanshu Maithani](http://divyanshu.xyz)
[β
](#tutorial-divyanshu013 "Tutorials") [πΉ](#video-divyanshu013 "Videos") | [
Deepak Grover](https://www.linkedin.com/in/metagrover)
[β
](#tutorial-metagrover "Tutorials") [πΉ](#video-metagrover "Videos") | [
Eyal Cohen](https://github.com/eyalcohen4)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=eyalcohen4 "Documentation") | [
Peter Makowski](https://github.com/petermakowski)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=petermakowski "Documentation") |
+| [
Michiel Nuyts](https://github.com/Michielnuyts)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=Michielnuyts "Documentation") | [
Joe Ng'ethe](https://github.com/joeynimu)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=joeynimu "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=joeynimu "Documentation") | [
Kate](https://github.com/Enikol)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=Enikol "Documentation") | [
Sean](http://www.seanrparker.com)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=SeanRParker "Documentation") | [
James Long](http://jlongster.com)
[π€](#ideas-jlongster "Ideas, Planning, & Feedback") [π¦](#platform-jlongster "Packaging/porting to new platform") | [
Herb Hagely](https://github.com/hhagely)
[π‘](#example-hhagely "Examples") | [
Alex Wendte](http://www.wendtedesigns.com/)
[π‘](#example-themostcolm "Examples") |
+| [
Monica Powell](http://www.aboutmonica.com)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=M0nica "Documentation") | [
Vitaly Sivkov](http://sivkoff.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=sivkoff "Code") | [
Weyert de Boer](https://github.com/weyert)
[π€](#ideas-weyert "Ideas, Planning, & Feedback") [π](#review-weyert "Reviewed Pull Requests") | [
EstebanMarin](https://github.com/EstebanMarin)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=EstebanMarin "Documentation") | [
Victor Martins](https://github.com/vctormb)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=vctormb "Documentation") | [
Royston Shufflebotham](https://github.com/RoystonS)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3ARoystonS "Bug reports") [π](https://github.com/kentcdodds/react-testing-library/commits?author=RoystonS "Documentation") [π‘](#example-RoystonS "Examples") | [
chrbala](https://github.com/chrbala)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=chrbala "Code") |
+| [
Donavon West](http://donavon.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=donavon "Code") [π](https://github.com/kentcdodds/react-testing-library/commits?author=donavon "Documentation") [π€](#ideas-donavon "Ideas, Planning, & Feedback") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=donavon "Tests") |
diff --git a/examples/__tests__/react-hooks.js b/examples/__tests__/react-hooks.js
new file mode 100644
index 00000000..3dd13b48
--- /dev/null
+++ b/examples/__tests__/react-hooks.js
@@ -0,0 +1,46 @@
+import {testHook, cleanup} from 'react-testing-library'
+
+import useCounter from '../react-hooks'
+
+afterEach(cleanup)
+
+test('accepts default initial values', () => {
+ let count
+ testHook(() => ({count} = useCounter()))
+
+ expect(count).toBe(0)
+})
+
+test('accepts a default initial value for `count`', () => {
+ let count
+ testHook(() => ({count} = useCounter({})))
+
+ expect(count).toBe(0)
+})
+
+test('provides an `increment` function', () => {
+ let count, increment
+ testHook(() => ({count, increment} = useCounter({step: 2})))
+
+ expect(count).toBe(0)
+ increment()
+ expect(count).toBe(2)
+})
+
+test('provides an `decrement` function', () => {
+ let count, decrement
+ testHook(() => ({count, decrement} = useCounter({step: 2})))
+
+ expect(count).toBe(0)
+ decrement()
+ expect(count).toBe(-2)
+})
+
+test('accepts a default initial value for `step`', () => {
+ let count, increment
+ testHook(() => ({count, increment} = useCounter({})))
+
+ expect(count).toBe(0)
+ increment()
+ expect(count).toBe(1)
+})
diff --git a/examples/react-hooks.js b/examples/react-hooks.js
new file mode 100644
index 00000000..fad0de4c
--- /dev/null
+++ b/examples/react-hooks.js
@@ -0,0 +1,10 @@
+import {useState} from 'react'
+
+function useCounter({initialCount = 0, step = 1} = {}) {
+ const [count, setCount] = useState(initialCount)
+ const increment = () => setCount(c => c + step)
+ const decrement = () => setCount(c => c - step)
+ return {count, increment, decrement}
+}
+
+export default useCounter
diff --git a/package.json b/package.json
index 919f0a36..3bb7c531 100644
--- a/package.json
+++ b/package.json
@@ -48,8 +48,8 @@
"jest-dom": "^2.0.4",
"jest-in-case": "^1.0.2",
"kcd-scripts": "^0.44.0",
- "react": "^16.5.2",
- "react-dom": "^16.5.2",
+ "react": "16.8.0",
+ "react-dom": "16.8.0",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
@@ -57,6 +57,7 @@
"redux": "^4.0.0"
},
"peerDependencies": {
+ "react": "*",
"react-dom": "*"
},
"eslintConfig": {
diff --git a/src/__tests__/testHook.js b/src/__tests__/testHook.js
new file mode 100644
index 00000000..f6bce9bd
--- /dev/null
+++ b/src/__tests__/testHook.js
@@ -0,0 +1,14 @@
+import {useState} from 'react'
+import 'jest-dom/extend-expect'
+import {testHook, cleanup} from '../'
+
+afterEach(cleanup)
+
+test('testHook calls the callback', () => {
+ const spy = jest.fn()
+ testHook(spy)
+ expect(spy).toHaveBeenCalledTimes(1)
+})
+test('confirm we can safely call a React Hook from within the callback', () => {
+ testHook(() => useState())
+})
diff --git a/src/index.js b/src/index.js
index 2f48a4e0..24b982ac 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,3 +1,4 @@
+import React from 'react'
import ReactDOM from 'react-dom'
import {getQueriesForElement, prettyDOM, fireEvent} from 'dom-testing-library'
@@ -51,6 +52,15 @@ function render(
}
}
+function TestHook({callback}) {
+ callback()
+ return null
+}
+
+function testHook(callback) {
+ render()
+}
+
function cleanup() {
mountedContainers.forEach(cleanupAtContainer)
}
@@ -92,6 +102,6 @@ fireEvent.select = (node, init) => {
// just re-export everything from dom-testing-library
export * from 'dom-testing-library'
-export {render, cleanup, flushEffects}
+export {render, testHook, cleanup, flushEffects}
/* eslint func-name-matching:0 */
diff --git a/typings/index.d.ts b/typings/index.d.ts
index aa01da17..ce6408f3 100644
--- a/typings/index.d.ts
+++ b/typings/index.d.ts
@@ -40,6 +40,11 @@ export function render(
options: RenderOptions,
): RenderResult
+/**
+ * Renders a test component that calls back to the test.
+ */
+export function testHook(callback: () => void): void
+
/**
* Unmounts React trees that were mounted with render.
*/