1.0.2 • Published 4 years ago

react-test-renderer-tree-to-json v1.0.2

Weekly downloads
13
License
MIT
Repository
github
Last release
4 years ago

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>
`; 
-----------------------*/