douglasjunior / react-native-recaptcha-that-works

⚛ A reCAPTCHA bridge for React Native that works (Android and iOS)
MIT License
165 stars 33 forks source link

Jest issue #26

Closed Zakyyy closed 2 years ago

Zakyyy commented 2 years ago

Here is how I implemented Recaptcha in my app

import React from 'react';
import RecaptchaV3 from 'react-native-recaptcha-that-works';
import {RECAPTCHA_SECRET, RECAPTCHA_DOMAIN} from '@env';

const Recaptcha = React.forwardRef(({onSuccess}, ref) => {
  const onVerifyRecaptcha = token => {
    onSuccess(token);
  };

  const onExpire = () => {
    console.warn('expired!');
  };
  return (
    <RecaptchaV3
      ref={ref}
      siteKey={RECAPTCHA_SECRET}
      baseUrl={RECAPTCHA_DOMAIN}
      onVerify={onVerifyRecaptcha}
      onExpire={onExpire}
      size="normal"
    />
  );
});

export default Recaptcha;

when I run npm test, I get the following error React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Anyone was able to solve this issue or have a mock file for the package.

Zakyyy commented 2 years ago

following up on this, I managed to pass the error by creating this mock file react-native-recaptcha-that-works.js inside mocks folder

import React from 'react';
import {View} from 'react-native';
const Recaptcha = props => <View {...props} />;
export default Recaptcha;
douglasjunior commented 2 years ago

I added some tests to the Sample project, but I don't need any mock to make it work.

image