24
24
[ ![ downloads] ( https://img.shields.io/npm/dm/react-hooks-testing-library.svg?style=flat-square )] ( http://www.npmtrends.com/react-hooks-testing-library )
25
25
[ ![ MIT License] ( https://img.shields.io/npm/l/react-hooks-testing-library.svg?style=flat-square )] ( https://github.com/mpeyper/react-hooks-testing-library/blob/master/LICENSE.md )
26
26
27
- [ ![ All Contributors] ( https://img.shields.io/badge/all_contributors-3 -orange.svg?style=flat-square )] ( #contributors )
27
+ [ ![ All Contributors] ( https://img.shields.io/badge/all_contributors-4 -orange.svg?style=flat-square )] ( #contributors )
28
28
[ ![ PRs Welcome] ( https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square )] ( http://makeapullrequest.com )
29
29
[ ![ Code of Conduct] ( https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square )] ( https://github.com/mpeyper/react-hooks-testing-library/blob/master/CODE_OF_CONDUCT.md )
30
30
@@ -148,6 +148,22 @@ Unmounts any React trees that were mounted with [renderHook](#renderhookcallback
148
148
149
149
This is the same [ ` cleanup ` function] ( https://testing-library.com/docs/react-testing-library/api#cleanup ) that is exported by ` react-testing-library ` .
150
150
151
+ Optionally, it is possible to import ` cleanup ` in a global test file. Using that way, it isn't necessary to run ` afterEach(cleanup) ` on every test script.
152
+
153
+ ``` js
154
+ // in package.json
155
+ " jest" : {
156
+ // ...
157
+ // use this if Jest version < 24
158
+ " setupTestFrameworkScriptFile" : " <rootDir>/src/setupTests.js" ,
159
+ // or if Jest version >= 24
160
+ " setupFilesAfterEnv" : [" <rootDir>/src/setupTests.js" ],
161
+ }
162
+
163
+ // src/setupTests.js
164
+ import ' react-hooks-testing-library/cleanup-after-each' ;
165
+ ```
166
+
151
167
### ` act(callback) `
152
168
153
169
This is the same [ ` act ` function] ( https://testing-library.com/docs/react-testing-library/api#act ) that is exported by ` react-testing-library ` .
@@ -158,7 +174,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
158
174
159
175
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
160
176
<!-- prettier-ignore -->
161
- <table><tr><td align="center"><a href="https://github.com/mpeyper"><img src="https://avatars0.githubusercontent.com/u/23029903?v=4" width="100px;" alt="Michael Peyper"/><br /><sub><b>Michael Peyper</b></sub></a><br /><a href="https://github.com/mpeyper/react-hooks-testing-library/commits?author=mpeyper" title="Code">💻</a> <a href="#design-mpeyper" title="Design">🎨</a> <a href="https://github.com/mpeyper/react-hooks-testing-library/commits?author=mpeyper" title="Documentation">📖</a> <a href="#ideas-mpeyper" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-mpeyper" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#platform-mpeyper" title="Packaging/porting to new platform">📦</a> <a href="https://github.com/mpeyper/react-hooks-testing-library/commits?author=mpeyper" title="Tests">⚠️</a> <a href="#tool-mpeyper" title="Tools">🔧</a></td><td align="center"><a href="https://github.com/otofu-square"><img src="https://avatars0.githubusercontent.com/u/10118235?v=4" width="100px;" alt="otofu-square"/><br /><sub><b>otofu-square</b></sub></a><br /><a href="https://github.com/mpeyper/react-hooks-testing-library/commits?author=otofu-square" title="Code">💻</a></td><td align="center"><a href="https://github.com/ab18556"><img src="https://avatars2.githubusercontent.com/u/988696?v=4" width="100px;" alt="Patrick P. Henley"/><br /><sub><b>Patrick P. Henley</b></sub></a><br /><a href="#ideas-ab18556" title="Ideas, Planning, & Feedback">🤔</a> <a href="#review-ab18556" title="Reviewed Pull Requests">👀</a></td></tr></table>
177
+ <table><tr><td align="center"><a href="https://github.com/mpeyper"><img src="https://avatars0.githubusercontent.com/u/23029903?v=4" width="100px;" alt="Michael Peyper"/><br /><sub><b>Michael Peyper</b></sub></a><br /><a href="https://github.com/mpeyper/react-hooks-testing-library/commits?author=mpeyper" title="Code">💻</a> <a href="#design-mpeyper" title="Design">🎨</a> <a href="https://github.com/mpeyper/react-hooks-testing-library/commits?author=mpeyper" title="Documentation">📖</a> <a href="#ideas-mpeyper" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-mpeyper" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#platform-mpeyper" title="Packaging/porting to new platform">📦</a> <a href="https://github.com/mpeyper/react-hooks-testing-library/commits?author=mpeyper" title="Tests">⚠️</a> <a href="#tool-mpeyper" title="Tools">🔧</a></td><td align="center"><a href="https://github.com/otofu-square"><img src="https://avatars0.githubusercontent.com/u/10118235?v=4" width="100px;" alt="otofu-square"/><br /><sub><b>otofu-square</b></sub></a><br /><a href="https://github.com/mpeyper/react-hooks-testing-library/commits?author=otofu-square" title="Code">💻</a></td><td align="center"><a href="https://github.com/ab18556"><img src="https://avatars2.githubusercontent.com/u/988696?v=4" width="100px;" alt="Patrick P. Henley"/><br /><sub><b>Patrick P. Henley</b></sub></a><br /><a href="#ideas-ab18556" title="Ideas, Planning, & Feedback">🤔</a> <a href="#review-ab18556" title="Reviewed Pull Requests">👀</a></td><td align="center"><a href="https://twitter.com/matiosfm"><img src="https://avatars3.githubusercontent.com/u/7120471?v=4" width="100px;" alt="Matheus Marques"/><br /><sub><b>Matheus Marques</b></sub></a><br /><a href="https://github.com/mpeyper/react-hooks-testing-library/commits?author=marquesm91" title="Code">💻</a></td></tr></table>
162
178
163
179
<!-- ALL-CONTRIBUTORS-LIST:END -->
164
180
0 commit comments