react/packages/react-test-renderer
Dominic Gannaway 4feab7fc92
Add hooks support to ReactShallowRenderer (#14567)
* Add hook support to ReactShallowRenderer
2019-01-17 17:42:27 +00:00
..
npm Use Yarn Workspaces (#11252) 2017-10-19 00:22:21 +01:00
src Add hooks support to ReactShallowRenderer (#14567) 2019-01-17 17:42:27 +00:00
README.md added link to reactjs docs for test renderer (#12293) 2018-03-03 22:25:29 -05:00
index.js Drop the year from Facebook copyright headers and the LICENSE file. (#13593) 2018-09-07 15:11:23 -07:00
package.json React v16.7.0 2018-12-19 17:23:14 -08:00
shallow.js Drop the year from Facebook copyright headers and the LICENSE file. (#13593) 2018-09-07 15:11:23 -07: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.

Documentation:

https://reactjs.org/docs/test-renderer.html

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.