嗨,我
正在尝试与此示例教程相同,但它给了我错误。
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"}
它返回未定义,因为源函数不是承诺函数。 这是普通函数。