Zac*_*hao 2 javascript testing jestjs expo
将我的项目从Expo45升级到Expo48后,我在运行测试时遇到此错误:
TypeError: Cannot read properties of undefined (reading 'exists')
at exists (node_modules/expo-asset/src/PlatformUtils.ts:65:17)
at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)
Run Code Online (Sandbox Code Playgroud)
单元测试本身非常简单:
it('Should be able rendered properly', () => {
render(
<UserContext.Provider
value={[initialState, jest.fn()]}
>
<UpdatePasswordScreen />
</UserContext.Provider>,
);
});
Run Code Online (Sandbox Code Playgroud)
UpdatePasswordScreen 组件是这样的:
<View style={styles.container}>
<Spinner
visible={showSpinner}
textContent={'Loading...'}
textStyle={{
color: '#FFFFFF',
}}
/>
<CustomInput
titleStyle={{
size: 13,
}}
titleContainerStyle={{
marginBottom: 10,
}}
containerStyle={{
marginBottom: 8,
}}
placeholder="Enter Password"
title="Old password"
value={oldPassword}
secureTextEntry={!showOldPassword}
onRenderLeftIcon={() => (
<Icon
name={showOldPassword ? 'eye' : 'eye-off'}
type="feather"
size={20}
color="#AFB4B9"
onPress={() => setShowOldPassword(!showOldPassword)}
/>
)}
onChangeText={setOldPassword}
/>
<View style={styles.confirmButton}>
<IconButton
text="Reset Password"
buttonStyle={{
height: 52,
width: 200,
}}
onPress={updatePassword}
disabled={!oldPassword || !newPassword
|| !confirmNewPassword || showPasswordErrorMessage()
|| newPassword !== confirmNewPassword
|| oldPasswordUnchanged
}
/>
</View>
</View>
Run Code Online (Sandbox Code Playgroud)
我只想渲染组件,但它不起作用。单元测试在Expo45下运行良好。
任何建议将不胜感激!
如何解决这个问题呢?
小智 9
我通过将这些行添加到我的笑话设置文件中来修复此错误:
jest.mock("expo-font");
jest.mock("expo-asset");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
920 次 |
最近记录: |