reactjs - 笑话教程中的异步测试
问题描述
嗨,我正在尝试与本示例教程相同,但它给了我错误。
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 之后开玩笑说 undefined
{"id":10002,"name":"test","passportNumber":"A1234568"}
解决方案
它返回 undefined 因为源函数不是承诺函数。这是简单的功能。
推荐阅读
- javafx - JavaFx 应用程序卡住了
- dialogflow-es - Dialogflow 混淆意图
- arrays - 如何使用 nil:NilClass 的未定义方法“[]”迭代多维数组?
- java - CSV 具有以 1000 分隔符作为逗号的数值。当这些被 OpenCSV 存储为字符串时,我如何取回实际值?
- php - Magic function for auto-invoke in php
- java - 无法在使用拉力休息 api 和 java 创建新测试用例时添加新标签
- javascript - 向 img 按钮添加功能
- php - 更新重复键创建新行(MYSQL-PHP)
- android - 如何使小吃店可点击?
- java - 如果出现错误,PreparedStatement 继续插入