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