运行jest测试时出现此错误。尝试了很多禁用prop types规则:
Warning: Failed prop type: Invalid prop `source` supplied to `Image`, expected one of type [number].
in Image (at Welcome.js:134)
in Welcome (created by Connect(Welcome))
in Connect(Welcome) (at Welcome.test.js:25)
in Provider (at Welcome.test.js:24)
132 | {!global.isFirstTime &&
133 | <TouchableOpacity style={styles.backIcon} onPress={() => props.navigation.goBack()}>
> 134 | <Image source={Images.back} />
| ^
135 | </TouchableOpacity>
136 | }
137 |
已在.eslintrc.json
中添加规则
"rules": {
"react/prop-types": 0
}
同时添加jest配置模块NameMapper
moduleNameMapper: {
'\\.(css|less)$': 'identity-obj-proxy',
'^(.+)\\.(jpg|jpeg|gif|png|mp4|mkv|avi|webm|swf|wav|mid)$': 'jest-static-stubs/$2'
},
因此,当测试运行时,Images.back包含:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==
1.“react”:“16.13.1”,
1.“react-native”:“0.63.5”,
1.“eslint”:“^8.39.0”,
1.“jest”:“26.6.3”,
谢谢。
1条答案
按热度按时间pcww981p1#
请尝试: