0

Component to be tested. this.props.children have child components of example.js

class Example extends component {
  constructor(){
      super(props);
      this.state={};
    }
   render() {
        <div>{this.props.children}</div>
     }
}

test case

it("should render  Example with children", () => {
    const wrapper = shallow(<Example {...props} />);
     expect(wrapper.find("div").text()).toBe(""); //
   });

how to test the child components passed ?

Thanks.

Akshay Gireesh
  • 97
  • 2
  • 10

1 Answers1

3

You can use like below

describe('Parent Component', () => {
   it('renders Child component', () => {
   const wrapper = shallow(<Parent store={store} />);
   expect(wrapper.find(Child).length).toEqual(1);
  });
});

Also if you want to test only child component div use like this

const wrapper = shallow(<MyComponent />);
expect(wrapper.find('Foo')).to.have.lengthOf(1);
Vishal Nai
  • 268
  • 1
  • 12