开玩笑的数据类型评估返回错误类型

发布于 2025-02-12 09:21:40 字数 1483 浏览 0 评论 0原文

我正在使用jestjs库来测试我的nodejs应用程序。在测试返回数据类型时,某些测试未能说收到的数据类型是其他预期的东西,但是返回的数据类型是不正确的。例如,我有一个日期字符串作为对象接收,但实际上是一个字符串。

  Received has value: [Error: expect(received).toBe(expected) // Object.is equality·
    Expected: "string"
    Received: "object"]

      82 |     expect(typeof response.data.getPublicDisinfectionByProductStage2[0].details[0].nextSampleDateRange).toBe("string");

正在评估响应对象:

 {
        "systemId": 1289,
        "frequency": "QT",   
        "details": [
          {
            "sampleId": 19842,
            "nextSampleDateRange": "04/01/2022 - 06/30/2022"
          }
]
}

然后使用类似的对象,测试失败而错误:


    expect(received).toMatch(expected)

    Matcher error: received value must be a string

    Received has type:  object
    Received has value: [Error: expect(received).toBe(expected) // Object.is equality·
    Expected: "number"
    Received: "object"]

      107 |     expect(typeof response.data.getPublicOtherDistributionMonitoringPbcu.nextSampleDateRange).toBe("string");
      108 |   } catch (e) {
    > 109 |     expect(e).toMatch("error");
          |               ^
      110 |   }
      111 | });

在哪里评估对象如下:

{
  "data": {
    "getPublicOtherDistributionMonitoringPbcu": {
      "systemId": 1289,
      "lastSampleDate": "2018-09-27 00:00:00",
      "nextSampleDateRange": "06/01/2022 - 09/30/2022"
    }
  }
}

有人可以帮助我了解这里发生了什么吗?

I am using the JestJS library to unit test my nodeJS application. When testing for returning data types, some tests are failing saying that the received data type is something other then what is expected, however the returned data type is incorrect. For example, I have a date string that is being received as an object, but it is in fact a string.

  Received has value: [Error: expect(received).toBe(expected) // Object.is equality·
    Expected: "string"
    Received: "object"]

      82 |     expect(typeof response.data.getPublicDisinfectionByProductStage2[0].details[0].nextSampleDateRange).toBe("string");

Response object being evaluated:

 {
        "systemId": 1289,
        "frequency": "QT",   
        "details": [
          {
            "sampleId": 19842,
            "nextSampleDateRange": "04/01/2022 - 06/30/2022"
          }
]
}

Then with a similar object the test fails with an error:


    expect(received).toMatch(expected)

    Matcher error: received value must be a string

    Received has type:  object
    Received has value: [Error: expect(received).toBe(expected) // Object.is equality·
    Expected: "number"
    Received: "object"]

      107 |     expect(typeof response.data.getPublicOtherDistributionMonitoringPbcu.nextSampleDateRange).toBe("string");
      108 |   } catch (e) {
    > 109 |     expect(e).toMatch("error");
          |               ^
      110 |   }
      111 | });

Where the object being evaluated looks like this:

{
  "data": {
    "getPublicOtherDistributionMonitoringPbcu": {
      "systemId": 1289,
      "lastSampleDate": "2018-09-27 00:00:00",
      "nextSampleDateRange": "06/01/2022 - 09/30/2022"
    }
  }
}

Can someone help me understand what's happening here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文