vnxyz
vnxyz

Reputation: 466

Test call back function sent to a child element using enzyme

There is a function in my parent class that is being sent to the Child component, it is not being used else where. How can I achieve coverage for this code. I want to avoid using mount and use shallow only.

class Parent extends React.Component {
  callBackFn() {
    console.log("Some call back function");
  }
  render(){
    return (<div>
        <ChildComponent someFunct="callBackFn" />
      </div>);

  }
}

Upvotes: 1

Views: 47

Answers (1)

Sanket Phansekar
Sanket Phansekar

Reputation: 741

let wrapper = shallow(<Parent/>);
wrapper.find(ChildComponent).prop('someFunct')();

This can execute your function and code will get covered.

Upvotes: 1

Related Questions