title: How to unit test a method of react component?
body: <p>I am trying to unit test my reactjs component:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import React from 'react';
  import Modal from 'react-modal';
  import store from '../../../store'
  import lodash from 'lodash'
  
  export class AddToOrder extends React.Component {
    constructor(props) {
      super(props);
      this.state = {checked: false}
      //debugger
    }
    checkBoxChecked() {
      return true
    }
    render() {
      console.log('testing=this.props.id',this.props.id )
      return (
        &lt;div className="order"&gt;
          &lt;label&gt;
            &lt;input
              id={this.props.parent}
              checked={this.checkBoxChecked()}
              onChange={this.addToOrder.bind(this, this.props)}
              type="checkbox"/&gt;
            Add to order
          &lt;/label&gt;
        &lt;/div&gt;
      )
    }
  }
  
  export default AddToOrder;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Just to get started I am already struggling to assert the checkBoxChecked method:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import React from 'react-native';
  import {shallow} from 'enzyme';
  import {AddToOrder} from '../app/components/buttons/addtoorder/addtoorder';
  import {expect} from 'chai';
  import {mount} from 'enzyme';
  import jsdom from 'jsdom';
  const doc = jsdom.jsdom('&lt;!doctype html&gt;&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;')
  global.document = doc
  global.window = doc.defaultView
  
  let props;
  beforeEach(() =&gt; {
    props = {
      cart: {
        items: [{
          id: 100,
          price: 2000,
          name:'Docs'
        }]
      }
    };
  });
  
  describe('AddToOrder component', () =&gt; {
    it('should be handling checkboxChecked', () =&gt; {
      const wrapper = shallow(&lt;AddToOrder {...props.cart} /&gt;);
      expect(wrapper.checkBoxChecked()).equals(true); //error appears here
    });
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>```</p>
  
  <p>How can I unit test a method on the component? This is the error I am getting:</p>
  
  <pre><code>TypeError: Cannot read property 'checked' of undefined
  </code></pre>