I implemented a React-Recaptcha Component, which I am trying to add few unit tests to it.
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).
<ReCAPTCHA sitekey={RECAPTCHA_SITE_KEY} onChange={value => this.setState({ gToken: value, recaptchaState: true })} />
and my tests has something like this
describe('RefundaModal Component', () => {
const modalcomponent = shallow(<RefundModalDialog />);
const captcha = shallow(<ReCAPTCHA sitekey={RECAPTCHA_SITE_KEY} onChange={() => {}} />);
test('render RefundModalDialog component', () => {
expect(modalcomponent.exists()).toBe(true);
});
test('user clicked on recaptcha', async () =>
modalcomponent.setState({ gToken: null, recaptchaState: false });
captcha.props().onChange();
expect(modalcomponent.state().recaptchaState).toEqual(true);
});
});
I also tried a different approach captcha.simulate('change'); but I keep receiving false when the intention is to receive true.
How would be the right way to implement such test ?
Thanks