react-test-renderer-tree-to-json
v1.0.2
Published
Convert React Test Renderer tree to a format compatible with Jest snapshot testing.
Downloads
858
Maintainers
Readme
react-test-renderer-tree-to-json
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>
`;
-----------------------*/