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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "legit-tests",
"version": "1.0.0",
"version": "1.1.0",
"description": "a chainable testing library for React",
"main": "legit-tests.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion src/middleware.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Find from './middleware/find'
import SetState from './middleware/setState'
import Simulate from './middleware/simulate'
import Clean from './middleware/clean'

export default {
Find,
SetState,
Simulate
Simulate,
Clean
}
7 changes: 7 additions & 0 deletions src/middleware/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Clean(){
this.instance = null
this.elements = null
if (global.window){
global.window.document.body.innerHTML = ''
}
}
10 changes: 8 additions & 2 deletions src/tests.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import TestUtils from 'react-addons-test-utils'
import ReactDOMServer from 'react-dom/server'
import ReactDOM from 'react-dom'
import React from 'react'
global.React = React

import { Find, SetState, Simulate } from './middleware'
import { Find, SetState, Simulate, Clean } from './middleware'

function Test(component, config) {

Expand All @@ -12,6 +13,10 @@ function Test(component, config) {
const shallowRenderer = TestUtils.createRenderer()
shallowRenderer.render(component)
instance = shallowRenderer.getRenderOutput()
} else if (config && config.fullDOM && global.window) {
var div = global.window.document.createElement('div')
global.window.document.body.appendChild(div)
instance = ReactDOM.render(component, div)
} else {
instance = TestUtils.renderIntoDocument(component)
}
Expand Down Expand Up @@ -69,7 +74,8 @@ function Test(component, config) {
return testComponent.mixin({
find: Find,
setState: SetState,
simulate: Simulate
simulate: Simulate,
clean: Clean
})
}

Expand Down
18 changes: 18 additions & 0 deletions tests/full-dom.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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.not.equal(null)
})
.clean()

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

})