我是单元测试/玩笑的新手,但我了解一些有关 React Native 的知识。我想为我的主屏幕编写一个测试,其中包含一个发出简单请求的组件。代码运行没有任何问题,但当我用 Jest 运行它时失败。
主屏.js
import { View } from 'react-native'
import APIExample from '@components/Examples/APIExample'
const HomeScreen = () => {
return (<View> <APIExample /> </View>)
}
export default HomeScreen
Run Code Online (Sandbox Code Playgroud)
HomeScreen.test.js
import { render } from '@testing-library/react-native'
import HomeScreen from '@screens/HomeScreen'
it('should run', async () => {
const { getByText } = await render(<HomeScreen />)
})
Run Code Online (Sandbox Code Playgroud)
APIExample.js
import { useState, useEffect } from 'react'
import { Text, View } from 'react-native'
import API from '../../API'
const APIExample = …Run Code Online (Sandbox Code Playgroud)