react-test-renderer-tree-to-json
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

react-test-renderer-tree-to-json

Build Status Coverage Status
npm Version License Downloads

Convert React Test Renderer tree to a format compatible with Jest snapshot testing.
This is similar to enzyme-to-json.

Install

$ npm i -D react-test-renderer-tree-to-json

Usage

Only for full rendering without key props.

import React from "react";
 
import TestRenderer from "react-test-renderer";
import { treeToJSON } from "react-test-renderer-tree-to-json";
 
import { mount } from "enzyme";
import toJson from "enzyme-to-json";
 
const Hoge = () => <div />;
 
it("snapshot", () => {
  const renderer = TestRenderer.create(<Hoge />);
  const tree = renderer.toTree();
  expect(treeToJSON(tree)).toMatchSnapshot();
  // similar to
  const wrapper = mount(<Hoge />);
  expect(toJson(wrapper, { noKey: true })).toMatchSnapshot();
});
/*-----------------------
exports[`snapshot 1`] = `
<Hoge>
  <div />
</Hoge>
`; 
-----------------------*/

Package Sidebar

Install

npm i react-test-renderer-tree-to-json

Weekly Downloads

30

Version

1.0.2

License

MIT

Unpacked Size

6.78 kB

Total Files

5

Last publish

Collaborators

  • mochiya98