From 828d2b6e46be41701c4543d51ca97aa5881ff396 Mon Sep 17 00:00:00 2001 From: Tim Hansen Date: Wed, 25 Jul 2018 09:17:57 +0200 Subject: [PATCH 1/2] Switch default baseElement to document.body; fixes dom-testing-library #81. --- README.md | 2 +- src/__tests__/render.js | 4 ++-- src/index.js | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 751e7c26..ca6b71f4 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ The containing DOM node of your rendered React Element (rendered using The containing DOM node where your React Element is rendered in the container. If you don't specify the `baseElement` in the options of `render`, it will -default to `documentElement`. +default to `document.body`. This is useful when the component you want to test renders something outside the container div, e.g. when you want to snapshot test your portal component which diff --git a/src/__tests__/render.js b/src/__tests__/render.js index b5c09b90..464b8fc2 100644 --- a/src/__tests__/render.js +++ b/src/__tests__/render.js @@ -50,9 +50,9 @@ test('works great with react portals', () => { expect(document.body.contains(portalNode)).toBe(false) }) -test('returns baseElement which defaults to document.documentElement', () => { +test('returns baseElement which defaults to document.body', () => { const {baseElement} = render(
) - expect(baseElement).toBe(document.documentElement) + expect(baseElement).toBe(document.body) }) it('cleansup document', () => { diff --git a/src/index.js b/src/index.js index 8993e012..b5e238aa 100644 --- a/src/index.js +++ b/src/index.js @@ -6,7 +6,9 @@ const mountedContainers = new Set() function render(ui, {container, baseElement = container} = {}) { if (!container) { - baseElement = document.documentElement + // default to document.body instead of documentElement to avoid output of potentially-large + // head elements (such as JSS style blocks) in debug output + baseElement = document.body container = document.body.appendChild(document.createElement('div')) } From b0b0151761be08aaf9cb1ea7f348a8709575a4ca Mon Sep 17 00:00:00 2001 From: Tim Hansen Date: Wed, 25 Jul 2018 09:31:20 +0200 Subject: [PATCH 2/2] add contributor to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca6b71f4..d2e6f61d 100644 --- a/README.md +++ b/README.md @@ -977,7 +977,7 @@ Thanks goes to these people ([emoji key][emojis]): | [
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") | +| [
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 Hansen](https://github.com/timbonicus)
[πŸ›](https://github.com/kentcdodds/dom-testing-library/issues?q=author=timbonicus)[πŸ’»](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Code")[⚠️](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Tests") |