diff --git a/package.json b/package.json index 1143309..a51b104 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/middleware.js b/src/middleware.js index 025f0c4..be0b2e5 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -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 } diff --git a/src/middleware/clean.js b/src/middleware/clean.js new file mode 100644 index 0000000..5864544 --- /dev/null +++ b/src/middleware/clean.js @@ -0,0 +1,7 @@ +export default function Clean(){ + this.instance = null + this.elements = null + if (global.window){ + global.window.document.body.innerHTML = '' + } +} \ No newline at end of file diff --git a/src/tests.js b/src/tests.js index 1801308..9843689 100644 --- a/src/tests.js +++ b/src/tests.js @@ -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) { @@ -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) } @@ -69,7 +74,8 @@ function Test(component, config) { return testComponent.mixin({ find: Find, setState: SetState, - simulate: Simulate + simulate: Simulate, + clean: Clean }) } diff --git a/tests/full-dom.jsx b/tests/full-dom.jsx new file mode 100644 index 0000000..fe0e57c --- /dev/null +++ b/tests/full-dom.jsx @@ -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(
, {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('') + }) + +}) \ No newline at end of file