30db14b1 | import React from 'react'; import Fragment from './fragment'; import ezJson from 'enzyme-to-json'; import {shallow} from 'enzyme'; it("should display when state is truthy", () => { // given const state = {property : true}; // 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 const state = {property : undefined}; // when |
27fb05ae | const wrapper = shallow( <Fragment state={state} filterOn="property"> <div>Hello</div> </Fragment> ); |
30db14b1 | // then expect(ezJson(wrapper)).toEqual(null); }); it("should handle paths in the state tree", () => { // given const state = {property : {subproperty: true}}; // 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 const state = {property : [{bar: {}}]}; // 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 const state = {property : {subproperty: true}}; |
27fb05ae | const wrapper = shallow( <Fragment state={state} filterOn="property.missingproperty.something"> <div>Hello</div> </Fragment> ); |
30db14b1 | expect(ezJson(wrapper)).toEqual(null); }); |