嗨,我正在尝试与本示例教程相同,但是它给了我错误。
https://jestjs.io/docs/en/tutorial-async
expect(received).toEqual(expected)
Expected value to equal:
"Paul"
Received:
undefined
Difference:
Comparing two different types of values. Expected string but received undefined.
14 | it('works with async/await and resolves', async () => {
15 | expect.assertions(1);
> 16 | await expect(user.getUserName(5)).resolves.toEqual('Paul');
| ^
17 | });
每一样都一样,我的服务器返回一个json,但在http get之后开玩笑说未定义
{"id":10002,"name":"test","passportNumber":"A1234568"}
答案 0 :(得分:0)
它返回未定义的,因为源函数不是promise函数。这是普通功能。