【发布时间】:2019-01-12 08:45:44
【问题描述】:
您好,我正在尝试与本示例教程相同,但它给了我错误。
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"}
【问题讨论】:
-
我会监视
getUserName并返回一个模拟的 Promise。测试不应该做 HTTP 请求,这些应该被模拟。 -
同教程
-
教程代码不起作用
标签: reactjs react-native jestjs