title: Jest Expected mock function to have been called, but it was not called
body: <p>I've looked at various suggestions to solve testing a class property with no success and was wondering if anyone could possibly cast a little more light on where I may be going wrong, here are the tests I've tried all with the error Expected mock function to have been called, but it was not called.</p>
  
  <p>Search.jsx</p>
  
  <pre><code>import React, { Component } from 'react'
  import { func } from 'prop-types'
  import Input from './Input'
  import Button from './Button'
  
  class SearchForm extends Component {
    static propTypes = {
      toggleAlert: func.isRequired
    }
  
    constructor() {
      super()
  
      this.state = {
        searchTerm: ''
      }
  
      this.handleSubmit = this.handleSubmit.bind(this)
    }
  
    handleSubmit = () =&gt; {
      const { searchTerm } = this.state
      const { toggleAlert } = this.props
  
      if (searchTerm === 'mocky') {
        toggleAlert({
          alertType: 'success',
          alertMessage: 'Success!!!'
        })
  
        this.setState({
          searchTerm: ''
        })
      } else {
        toggleAlert({
          alertType: 'error',
          alertMessage: 'Error!!!'
        })
      }
    }
  
    handleChange = ({ target: { value } }) =&gt; {
      this.setState({
        searchTerm: value
      })
    }
  
    render() {
      const { searchTerm } = this.state
      const btnDisabled = (searchTerm.length === 0) === true
  
      return (
        &lt;div className="well search-form soft push--bottom"&gt;
          &lt;ul className="form-fields list-inline"&gt;
            &lt;li className="flush"&gt;
              &lt;Input
                id="search"
                name="search"
                type="text"
                placeholder="Enter a search term..."
                className="text-input"
                value={searchTerm}
                onChange={this.handleChange}
              /&gt;
              &lt;div className="feedback push-half--right" /&gt;
            &lt;/li&gt;
            &lt;li className="push-half--left"&gt;
              &lt;Button className="btn btn--positive" disabled={btnDisabled} onClick={this.handleSubmit}&gt;
                Search
              &lt;/Button&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/div&gt;
      )
    }
  }
  
  export default SearchForm
  </code></pre>
  
  <p>First option:</p>
  
  <pre><code>it('should call handleSubmit function on submit', () =&gt; {
      const wrapper = shallow(&lt;Search toggleAlert={jest.fn()} /&gt;)
      const spy = jest.spyOn(wrapper.instance(), 'handleSubmit')
      wrapper.instance().forceUpdate()
      wrapper.find('.btn').simulate('click')
      expect(spy).toHaveBeenCalled()
      spy.mockClear()
    })
  </code></pre>
  
  <p>Second option:</p>
  
  <pre><code>it('should call handleSubmit function on submit', () =&gt; {
      const wrapper = shallow(&lt;Search toggleAlert={jest.fn()} /&gt;)
      wrapper.instance().handleSubmit = jest.fn()
      wrapper.update()
      wrapper.find('.btn').simulate('click')
      expect(wrapper.instance().handleSubmit).toHaveBeenCalled()
    })
  </code></pre>
  
  <p>I get that with a class property the function is an instance of the class requiring the component to be updated in order to register the function, it looks however like the component handleSubmit function gets called instead of the mock?</p>
  
  <p>Swapping out handleSubmit to be a class function as a method gives me access on the class prototype which passes the test when spying on Search.prototype but I'd really like to get a solution to the class property approach. </p>
  
  <p>All suggestions and recommendations would be grateful!</p>