--- id: test-renderer title: Test Renderer permalink: docs/test-renderer.html layout: docs category: Reference --- **Importing** ```javascript import TestRenderer from 'react-test-renderer'; // ES6 const TestRenderer = require('react-test-renderer'); // ES5 with npm ``` ## Overview This package provides a 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 platform view hierarchy (similar to a DOM tree) rendered by a React DOM or React Native component without using a browser or [jsdom](https://github.com/tmpvar/jsdom). Example: ```javascript import TestRenderer from 'react-test-renderer'; function Link(props) { return {props.children}; } const testRenderer = TestRenderer.create( Facebook ); console.log(testRenderer.toJSON()); // { type: 'a', // props: { href: 'https://www.facebook.com/' }, // children: [ 'Facebook' ] } ``` You can 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: [Learn more about it](http://facebook.github.io/jest/blog/2016/07/27/jest-14.html). You can also traverse the output to find specific nodes and make assertions about them. ```javascript import TestRenderer from 'react-test-renderer'; function MyComponent() { return (
Hello
Sub
); } const testRenderer = TestRenderer.create(