title: React Unit tests for Google Recaptcha v2
body: <p>I implemented a React-Recaptcha Component, which I am trying to add few unit tests to it.</p>
  
  <p>Among other things, Im trying to test if the state of my component has changed (which should be the token received after checking the box).</p>
  
  <pre><code>&lt;ReCAPTCHA sitekey={RECAPTCHA_SITE_KEY} onChange={value =&gt; this.setState({ gToken: value, recaptchaState: true })} /&gt;
  </code></pre>
  
  <p>and my tests has something like this</p>
  
  <pre><code>describe('RefundaModal Component', () =&gt; {
    const modalcomponent = shallow(&lt;RefundModalDialog /&gt;);
    const captcha = shallow(&lt;ReCAPTCHA sitekey={RECAPTCHA_SITE_KEY} onChange={() =&gt; {}} /&gt;);
    test('render RefundModalDialog component', () =&gt; {
      expect(modalcomponent.exists()).toBe(true);
    });
    test('user clicked on recaptcha', async () =&gt;
      modalcomponent.setState({ gToken: null, recaptchaState: false });
      captcha.props().onChange();
      expect(modalcomponent.state().recaptchaState).toEqual(true);
    });
  });
  </code></pre>
  
  <p>I also tried a different approach <code>captcha.simulate('change');</code> but I keep receiving false when the intention is to receive true.</p>
  
  <p>How would be the right way to implement such test ?</p>
  
  <p>Thanks</p>