I am new to reactJS and try to learn how to test with it. I have encouter the following testing util method. However i am keep getting the same error message:ReferenceError: document is not defined
.
renderIntoDocument
ReactComponent renderIntoDocument(
ReactElement instance
)
Render a component into a detached DOM node in the document. This function requires a DOM.
Note: You will need to have window, window.document and window.document.createElement globally available before you import React. Otherwise React will think it can't access the DOM and methods like setState won't work.
I know it the reason failing its missing the DOM, but how can i insert the DOM or require it?
My test below:
import expect from 'expect.js';
import React from 'react';
import Header from '../../components/header';
import {renderShallow} from './help';
import ReactAddOn from 'react/addons';
var TestUtils = ReactAddOn.addons.TestUtils;
describe('Test react', function() {
let component;
beforeEach(()=>{
component = TestUtils.renderIntoDocument(<Header></Header>);
});
it('Test if the content been correclty render', function() {
console.log(component);
});
});
renderIntoDocument
and where exactly the error is coming from? – Pulpreact-dom
and split each addOn into its own package. For example,TestUtlis
are now inreact-addons-test-utils
. You might have some issues with dependencies. – Pulp