Mistake: Missing 等待
找错误 中等
题目
什么是 错误使用这个异步测试?
代码
test('async test', () => {
const result = fetchData();
expect(result).toBe('data');
});
提示
fetchData 返回 Promise, 不 resolved 值.
解释
The mistake is not awaiting the async call. fetchData() returns a Promise, not the resolved value. The assertion compares a Promise to 'data', which will always fail. The fix: make the callback async and add await: test('async test', async () => { const result = await fetchData(); expect(result).toBe('data'); });.
相关资源
相关课程
- 异步测试
测试 asynchronous code.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。