0

Getting this prop types error only in jest test run:

Warning: Failed prop type: Invalid prop `source` supplied to `Image`, expected one of type [number]


//Images declaration:
const Images = {
...
back: require('../assets/images/back.png'),
...

//Component snip which is  giving prop types error

<Image source={Images.back} />

The problem in jest fixes and test passes when using

<Image source={{uri: Images.back}} />

But since this is a static file, crashes in the app. Im using a module mapper for static file in jest.config.js

moduleNameMapper: {
    '\\.(css|less)$': 'identity-obj-proxy',
    '^(.+)\\.(jpg|jpeg|gif|png|mp4|mkv|avi|webm|swf|wav|mid)$': 'jest-static-stubs/$2'
},

so Image.back is giving out data:uri.

Please help on how to correctly configure jest or to resolve the prop types error? Thanks you.

"react": "16.13.1"
"react-native": "0.63.5 "
"jest": "26.6.3",
        
thevikas
  • 1,618
  • 1
  • 14
  • 31
  • Does this https://stackoverflow.com/questions/36460827/react-native-failed-proptype-on-image-component answer your question? – Lin Du Apr 27 '23 at 08:33

0 Answers0