calintamas / react-native-toast-message

Animated toast message component for React Native
MIT License
1.73k stars 265 forks source link

● renders correctly Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of `PopupNotification`. #426

Open vijaygojiya opened 2 years ago

vijaygojiya commented 2 years ago

import React from 'react'; import { FlatList, Image, View } from 'react-native'; import Toast from 'react-native-toast-message';

import MAIN_IMAGES from '../../modules/main/assets/images'; import { passwordErrors } from '../../modules/main/src/mainConstant'; import ItemValidationError from '../itemValidationError'; import ParagraphText from '../paragraphText'; import styles from './styles';

const PopupNotification = () => { const renderError = (props) => { return <ItemValidationError {...props} />; }; const toastConfig = { success: ({ text1 }) => (

{text1}
),
passwordValidationErrorToast: () => (
  <View style={styles.container}>
    <Image source={MAIN_IMAGES.IC_NOTIFIVATION_BELL} />
    <FlatList
      keyExtractor={(_, index) => index.toString()}
      data={passwordErrors}
      renderItem={renderError}
    />
  </View>
),

};

return <Toast config={toastConfig} ref={(ref) => Toast.setRef(ref)} />; };

export default PopupNotification; `

vijaygojiya commented 2 years ago

test cases are failing image

vijaygojiya commented 2 years ago

Resolved by mock the component

jest.mock('../src/components/popupValidation/', () => () => { const MockPopUpNotification = 'PopupNotification' as unknown as React.FC; return ; });

babarbahadur commented 5 months ago

@vijaygojiya I need help brother. I also have a reusuable component and tried to copy paste your code but it does not work. Could you please check it again and share the correct mock?