react-jsdom
v3.0.0
Published
Render React components to actual DOM nodes in Node.js
Downloads
2,190
Readme
react-jsdom
Render React components to actual DOM nodes in Node.js
Makes testing simple React components super easy with any Node.js test framework.
Install
npm install --save-dev react-jsdom
Usage
const React = require('react');
const ReactJSDOM = require('react-jsdom');
class Hi extends React.Component {
render() {
return (
<div>
<span>hi</span>
<span>{this.props.person}</span>
</div>
);
}
componentDidMount() {
console.log('I mounted!');
}
}
const elem = ReactJSDOM.render(<Hi person="mum"/>);
// console: 'I mounted!'
elem.constructor.name
// 'HTMLDivElement'
elem.nodeName;
// 'DIV');
elem.querySelector('span:last-child').textContent;
// 'mum'
elem.outerHTML;
// <div>
// <span>hi</span>
// <span>mum</span>
// </div>
License
MIT © Luke Childs