Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rendering into the document.body #38

Merged
merged 3 commits into from
Feb 19, 2016
Merged

Conversation

NickStefan
Copy link
Contributor

When possible, its good to use the shallow rendering (less overhead).
Other times, we use full jsdom, but only to render into a document fragment (the default for React tests).

I've had some use cases where I actually benefited from rendering into the actual document.body of the jsdom instance.

For example, you can't always avoid using a jquery plugin, and it's easier to test these integrations in an actual body element. Its more overhead, but it's still way way less than running something like selenium / webdriver.

The test I added should demonstrate the API. Basically, its just a new flag, and everything else works as normal, except that you need to call .clean() at the end of the test.

import Test from '../src/legit-tests'
import { expect } from 'chai'

describe('Render into document.body', () => {

  it('should render and clean up component', () => {
    Test(<section />, {fullDOM: true})
    .test(function() {
      expect(global.window.document.querySelector('section'))
      .to.be.okay
    })
    .clean()

    // clean should clean up the document.body
    expect(global.window.document.body.innerHTML).to.equal('')
  })

})

@zackify
Copy link
Member

zackify commented Feb 19, 2016

Sounds fine to me. If you could add this to the docs that would be nice

zackify added a commit that referenced this pull request Feb 19, 2016
Allow rendering into the document.body
@zackify zackify merged commit 3a26bdf into Legitcode:master Feb 19, 2016
@zackify
Copy link
Member

zackify commented Feb 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants