首页 > 解决方案 > 笑话教程中的异步测试

问题描述

嗨,我正在尝试与本示例教程相同,但它给了我错误。

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"}

标签: reactjsreact-nativejestjs

解决方案


它返回 undefined 因为源函数不是承诺函数。这是简单的功能。


推荐阅读