diff --git a/README.md b/README.md index 751e7c26..d2e6f61d 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 @@ -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") | 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')) }