title: ReactJS/Enzyme: How to test a submit function, which calls a graphQL mutation via prop
body: <p>I'm trying to write a unit test (enzyme/jest) for this function:</p>
  
  <pre><code>_onSubmit = (event) =&gt; {
    event.preventDefault()
    const { username, password } = this.state
  
    this.props.createUserMutation({
      variables: { username, password }
    }).then(response =&gt; {
      const token = response.data.createUser.token
      if (token) {
          this.setState({ token })
      }
    }).catch(error =&gt; {
      console.warn(error)
    })
  }
  </code></pre>
  
  <p>But I don't know how to handle <code>this.props.createUserMutation()</code> for proper testing.</p>
  
  <p>Of course my current attempt throws a <code>TypeError: _this.props.createUserMutation is not a function</code> error</p>
  
  <p><strong>Unit test</strong></p>
  
  <pre><code>it('_onSubmit() should submit form and reset state object', () =&gt; {
    const wrapper = shallow(&lt;CreateAccount /&gt;)
    wrapper.setState({ username: 'Username', password: 'Password' })
    wrapper.find(Form).simulate('submit', {
      preventDefault: () =&gt; {}
    })
    const state = wrapper.instance().state
    expect(state).toEqual({ token: 'test' })
  })
  </code></pre>
  
  <hr>
  
  <p><strong>Updated unit test</strong></p>
  
  <pre><code>it('_onSubmit() should submit data and get result dataset', () =&gt; {
      const createUserMutation = () =&gt; {
        return Promise.resolve({
          data: {
            createUser: { token: 'token' }
          }
        })
      }
      const wrapper = shallow(&lt;CreateAccount createUserMutation={createUserMutation} /&gt;)
      wrapper.find(Form).simulate('submit', {
        preventDefault: () =&gt; {}
      })
      const state = wrapper.instance().state
      expect(state).toEqual({ token: 'token' })
    })
  </code></pre>
  
  <p><code>console.log(state)</code> doesn't give me a <code>token</code>.</p>