我有一个学生组件
function Student(props)
{
const [studentData,setStudentData]=useState([]);
function getStudentData()
{
axios
.get("myAPI/getStudentData")
.then {}
.catch(error=>
{
console.log(error);
}
}
useEffect(()=>{
getStudentData();
},[]);
}
我的React测试如下:
it('failure', async()=>
{
const api = Promise.reject('API has failed');
axios.get.mockImplementation(()=> api);
render(<Student />);
///Here how to test if I am getting 'API has failed' in console ?
expect('API has failed').toBeInTheDocument()???????
})
我的问题是:当我放置 debug() 时,我可以看到控制台输出中打印了“API 已失败”但是如何使用“expect”之类的东西来测试它?