【问题标题】:How to mock .then() and .catch() in Jest? [closed]如何在 Jest 中模拟 .then() 和 .catch()? [关闭]
【发布时间】:2021-11-08 11:35:04
【问题描述】:

谁能给我一个示例,说明如何在 Jest 中模拟 .then() 块和 .catch() 块 我正在尝试测试 AWS cognito.signUp().then().catch() 但返回 TypeError: cognito.signUp(...).then(...).catch is not a function

【问题讨论】:

    标签: javascript amazon-web-services jestjs mocking amazon-cognito


    【解决方案1】:

    本例中的thencatch 是与Promises 相关的函数。所以你可能想要在这里做的是模拟 cognito.signUp 函数来返回一个承诺。

    你可以从这里找到一个例子:https://jestjs.io/docs/tutorial-async

    【讨论】:

      猜你喜欢
      • 2021-10-31
      • 2018-04-23
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      • 2021-06-09
      • 2021-11-02
      • 2019-12-26
      • 2021-08-20
      相关资源
      最近更新 更多