2021年3月10日星期三

TypeError: Cannot read property 'map' of undefined ? Jest / React Native

I have an image slider component to display images from my Firebase database as follows ,

import React from 'react';  import Swiper from 'react-native-swiper';  import { View, StyleSheet, Image } from 'react-native'      const ImageSlider = ({images}) => {      return (          <Swiper autoplayTimeout={5}              style={styles.wrapper}              showsButtons={false}              loadMinimal={true}              showsPagination={true}              paginationStyle={styles.paginationStyle}              activeDotStyle={styles.activeDotStyle}              dotStyle={styles.dotStyle}              loop={true} autoplay={true}          >              {images.map((data, index) => {                  return (                      <View key={index} style={styles.slider}>                          <Image style={styles.itemImage} source= />                      </View>                  )              })}          </Swiper>      )  }  

For test above component I used follwing test file ,

import React from 'react';  import renderer from 'react-test-renderer';  import ImageSlider from '../../../src/components/imageSlider/ImageSlider';      test('renders correctly', () => {    const tree = renderer.create(<ImageSlider />).toJSON();    expect(tree).toMatchSnapshot();  });  

When I'm run npm test command and after I got following error

TypeError: Cannot read property 'map' of undefined  

Can anyone help me to slove this problem , Thank you

https://stackoverflow.com/questions/66576315/typeerror-cannot-read-property-map-of-undefined-jest-react-native March 11, 2021 at 12:06PM

没有评论:

发表评论