面临警告:失败的道具类型:提供给`Image` 的道具`source` 无效在 react-native (expo) 中运行 jest 测试用例时

问题描述

以下是错误代码: Warning: Failed prop type: Invalid prop 'source' supplied to 'Image'.

const ParentComponent = () => {
 return (
  <Image source={require('app/assets/image.png')}/>
 );
}

我已将 package.json 中的 name 配置定义为 app

我在运行玩笑测试时收到此错误。

解决方法

您需要提供照片的相对路径,例如:

  <Image source={require('../../assets/image.png')}/>

(取决于文件位置)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...