git.fiddlerwoaroof.com
src/fragment.test.js
84348047
 import React from "react";
 import Fragment from "./fragment";
 import ezJson from "enzyme-to-json";
 import { shallow } from "enzyme";
 import Enzyme from "enzyme";
 import Adapter from "enzyme-adapter-react-16";
cb71ce92
 Enzyme.configure({ adapter: new Adapter() });
30db14b1
 
 it("should display when state is truthy", () => {
   // given
84348047
   const state = { property: true };
30db14b1
   // when
 
27fb05ae
   const wrapper = shallow(
     <Fragment state={state} filterOn="property">
30db14b1
       <div>Hello</div>
27fb05ae
     </Fragment>
   );
30db14b1
 
   // then
   expect(ezJson(wrapper)).toMatchSnapshot();
 });
 
 it("should not display when state is falsy", () => {
   // given
84348047
   const state = { property: undefined };
30db14b1
   // when
 
27fb05ae
   const wrapper = shallow(
     <Fragment state={state} filterOn="property">
       <div>Hello</div>
     </Fragment>
   );
30db14b1
 
   // then
cb71ce92
   expect(ezJson(wrapper)).toBeFalsy();
30db14b1
 });
 
 it("should handle paths in the state tree", () => {
   // given
84348047
   const state = { property: { subproperty: true } };
30db14b1
   // when
 
27fb05ae
   const wrapper = shallow(
     <Fragment state={state} filterOn="property.subproperty">
       <div>Hello</div>
     </Fragment>
   );
30db14b1
 
   // then
   expect(ezJson(wrapper)).toMatchSnapshot();
 });
 
 it("should handle arrays in the state tree", () => {
   // given
84348047
   const state = { property: [{ bar: {} }] };
30db14b1
   // when
 
27fb05ae
   const wrapper = shallow(
     <Fragment state={state} filterOn="property.0.bar">
       <div>Hello</div>
     </Fragment>
   );
30db14b1
 
   // then
   expect(ezJson(wrapper)).toMatchSnapshot();
 });
 
 it("should be falsy if missing state tree", () => {
   // given
84348047
   const state = { property: { subproperty: true } };
30db14b1
 
27fb05ae
   const wrapper = shallow(
     <Fragment state={state} filterOn="property.missingproperty.something">
       <div>Hello</div>
     </Fragment>
   );
30db14b1
 
cb71ce92
   expect(ezJson(wrapper)).toBeFalsy();
30db14b1
 });