【问题标题】:How to test CRUD operations using Node.js postgres如何使用 Node.js postgres 测试 CRUD 操作
【发布时间】:2015-04-10 22:38:52
【问题描述】:

在我的 createreadupdatedelete 函数中,如果交易成功,我将返回 true,否则返回 false - 除了 read,我在其中返回请求datanull

此策略应该使测试变得容易,因为只需评估给定测试数据库的各种测试输入的返回值。

我的问题是,直到db.query("...") 完成并调用它的回调,我才能完全确定事务是否成功,但是此时,原始的 CRUD 函数已经返回。

常见的做法是什么?

【问题讨论】:

    标签: node.js postgresql unit-testing testing crud


    【解决方案1】:

    Javascript 是异步的,您肯定想了解在使用 node 时它是如何工作的。

    网上有很多关于这个的信息,但这里有一个答案:

    Understanding Asynchronous Code in Layman's terms

    一般来说,您的最佳实践是使用 Promise。 Promise 非常有用,但也需要一些时间来学习。我个人使用 Q Promise 库

    https://github.com/kriskowal/q

    我真的希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 2016-10-01
      • 1970-01-01
      • 2015-01-31
      • 2021-05-23
      • 2014-08-28
      • 1970-01-01
      相关资源
      最近更新 更多