Skip to content

Render React components to actual DOM nodes in Node.js

License

Notifications You must be signed in to change notification settings

lukechilds/react-jsdom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-jsdom

Render React components to actual DOM nodes in Node.js

Build Status Coverage Status npm

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

About

Render React components to actual DOM nodes in Node.js

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published