From a65a7d8c217595942c5c03b173120f218c0e0d83 Mon Sep 17 00:00:00 2001
From: MarkFalconbridge
Date: Tue, 19 Mar 2019 14:46:11 +0000
Subject: [PATCH] fix: reorder cleanupAtContainer code
Closes https://github.com/kentcdodds/react-testing-library/issues/326
---
.all-contributorsrc | 10 ++++++++++
README.md | 4 ++--
src/__tests__/render.js | 4 +++-
src/index.js | 2 +-
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 076f4205..de679507 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -698,6 +698,16 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "MarkFalconbridge",
+ "name": "MarkFalconbridge",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/20678943?v=4",
+ "profile": "https://github.com/MarkFalconbridge",
+ "contributions": [
+ "bug",
+ "code"
+ ]
}
],
"contributorsPerLine": 7
diff --git a/README.md b/README.md
index 890fa52b..d6c46844 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ practices.
[![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]
@@ -221,7 +221,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [
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") | [
Richard Maisano](https://github.com/maisano)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=maisano "Code") | [
Marco Biedermann](https://www.marcobiedermann.com)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=marcobiedermann "Code") [π§](#maintenance-marcobiedermann "Maintenance") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=marcobiedermann "Tests") | [
Alex Zherdev](https://github.com/alexzherdev)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Aalexzherdev "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=alexzherdev "Code") | [
AndrΓ© Matulionis dos Santos](https://twitter.com/Andrewmat)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=Andrewmat "Code") [π‘](#example-Andrewmat "Examples") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=Andrewmat "Tests") | [
Daniel K.](https://github.com/FredyC)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3AFredyC "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=FredyC "Code") [π€](#ideas-FredyC "Ideas, Planning, & Feedback") [β οΈ](https://github.com/kentcdodds/react-testing-library/commits?author=FredyC "Tests") | [
mohamedmagdy17593](https://github.com/mohamedmagdy17593)
[π»](https://github.com/kentcdodds/react-testing-library/commits?author=mohamedmagdy17593 "Code") |
-| [
Loren βΊοΈ](http://lorensr.me)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=lorensr "Documentation") |
+| [
Loren βΊοΈ](http://lorensr.me)
[π](https://github.com/kentcdodds/react-testing-library/commits?author=lorensr "Documentation") | [
MarkFalconbridge](https://github.com/MarkFalconbridge)
[π](https://github.com/kentcdodds/react-testing-library/issues?q=author%3AMarkFalconbridge "Bug reports") [π»](https://github.com/kentcdodds/react-testing-library/commits?author=MarkFalconbridge "Code") |
This project follows the [all-contributors][all-contributors] specification.
diff --git a/src/__tests__/render.js b/src/__tests__/render.js
index 0ffe1322..74adf5ea 100644
--- a/src/__tests__/render.js
+++ b/src/__tests__/render.js
@@ -57,14 +57,16 @@ test('returns baseElement which defaults to document.body', () => {
it('cleansup document', () => {
const spy = jest.fn()
+ const divId = 'my-div';
class Test extends React.Component {
componentWillUnmount() {
+ expect(document.getElementById(divId)).toBeInTheDocument()
spy()
}
render() {
- return
+ return
}
}
diff --git a/src/index.js b/src/index.js
index d2661920..c07bd000 100644
--- a/src/index.js
+++ b/src/index.js
@@ -78,10 +78,10 @@ function cleanup() {
// maybe one day we'll expose this (perhaps even as a utility returned by render).
// but let's wait until someone asks for it.
function cleanupAtContainer(container) {
+ ReactDOM.unmountComponentAtNode(container)
if (container.parentNode === document.body) {
document.body.removeChild(container)
}
- ReactDOM.unmountComponentAtNode(container)
mountedContainers.delete(container)
}