"Fossies" - the Fresh Open Source Software Archive

Member "react-16.12.0/packages/react-test-renderer/README.md" (12 Nov 2019, 1011 Bytes) of package /linux/www/react-16.12.0.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.


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.




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

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

// { 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.