在使用嘲笑调用AWS函数时面对问题

发布于 2025-02-12 18:25:53 字数 682 浏览 1 评论 0原文

public async sendToSQS(data){
  return new Promise((resolve, reject) => {
    AWS.config.update({...this.awsConfig});
    const sqs = new AWS.SQS();
    const params = {
      MessageBody: JSON.stringify(data),
      QueueUrl: queueUrl,
    };
    sqs.sendMessage(params, (error, data) => {
      if (error) {
        return reject(error);
      } else {
        return resolve(data.MessageId);
      }
    });
  });
}

并从这样的测试柜中调用它:

await sqsFile.sendToSQS("test data");

如果像开玩笑这样的错误检测到以下1个打开的手柄,可能会阻止开玩笑在sqs.sendmessage上退出。 有人可以帮我吗?我已经尝试了所有的方式,但我不想在package.json中使用 - forceexit。 为什么我会遇到这个错误?由于AWS,我该如何关闭这个开放处理程序?

public async sendToSQS(data){
  return new Promise((resolve, reject) => {
    AWS.config.update({...this.awsConfig});
    const sqs = new AWS.SQS();
    const params = {
      MessageBody: JSON.stringify(data),
      QueueUrl: queueUrl,
    };
    sqs.sendMessage(params, (error, data) => {
      if (error) {
        return reject(error);
      } else {
        return resolve(data.MessageId);
      }
    });
  });
}

And calling it from testcases like this:

await sqsFile.sendToSQS("test data");

And if an getting the error like Jest has detected the following 1 open handle potentially keeping Jest from exiting at sqs.sendMessage.
Can anybody help me out in this? I have tried all the ways and I don't want to use the --forceExit in the package.json and don't want to create a mock function.
Why i am getting this error? how can i close this open handler which is because of aws?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窝囊感情。 2025-02-19 18:25:53

解决。
这与承诺一起起作用。

await sqs.sendMessage(params).promise();

Resolved.
This works with the Promise.

await sqs.sendMessage(params).promise();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文