react/packages/react-test-renderer
Andrew Clark 4d0e8fc487
ReactDOM.createRoot creates an async root (#11769)
Makes createRoot the opt-in API for async updates. Now we don't have
to check the top-level element to see if it's an async container.
2017-12-04 14:34:02 -08:00
..
npm Use Yarn Workspaces (#11252) 2017-10-19 00:22:21 +01:00
src ReactDOM.createRoot creates an async root (#11769) 2017-12-04 14:34:02 -08:00
README.md Update README URLS to HTTPS (#11635) 2017-11-27 18:13:41 -08:00
index.js react-test-renderer: convert vars into let/const (#11731) 2017-12-01 00:01:45 +00:00
package.json Updating package versions for release 16.2.0 2017-11-28 13:26:36 -08:00
shallow.js react-test-renderer: convert vars into let/const (#11731) 2017-12-01 00:01:45 +00:00

README.md

react-test-renderer

This package provides an experimental React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment.

Essentially, this package makes it easy to grab a snapshot of the "DOM tree" rendered by a React DOM or React Native component without using a browser or jsdom.

Usage:

const ReactTestRenderer = require('react-test-renderer');

const renderer = ReactTestRenderer.create(
  <Link page="https://www.facebook.com/">Facebook</Link>
);

console.log(renderer.toJSON());
// { type: 'a',
//   props: { href: 'https://www.facebook.com/' },
//   children: [ 'Facebook' ] }

You can also use Jest's snapshot testing feature to automatically save a copy of the JSON tree to a file and check in your tests that it hasn't changed: https://facebook.github.io/jest/blog/2016/07/27/jest-14.html.