UNPKG

1.01 kBMarkdownView Raw
1# `react-test-renderer`
2
3This 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.
4
5Essentially, 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.
6
7Documentation:
8
9[https://reactjs.org/docs/test-renderer.html](https://reactjs.org/docs/test-renderer.html)
10
11Usage:
12
13```jsx
14const ReactTestRenderer = require('react-test-renderer');
15
16const renderer = ReactTestRenderer.create(
17 <Link page="https://www.facebook.com/">Facebook</Link>
18);
19
20console.log(renderer.toJSON());
21// { type: 'a',
22// props: { href: 'https://www.facebook.com/' },
23// children: [ 'Facebook' ] }
24```
25
26You 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.