在node.js中对unit testing中的依赖关系进行存根

我从node.jsunit testing开始,并且一直在研究node.js中最常用的unit testing框架。 我想从最常用的框架开始,使事情变得简单,因为可能有更多的信息。 据许多网站可能是摩卡。

虽然我理解这个模块来进行集成testing,但我并不知道如何使用诸如存根依赖之类的特性来处理它。 我已经看到摩卡不提供模拟/存根function,所以我不知道人们通常如何处理这些问题。

所以我想知道现在最stream行的unit testing模块是什么模块,依存关系……一个简短的例子会很棒。

谢谢

目前在许多node.js项目中组合在一起的模块似乎是:

  • 摩卡的实际testing线束本身
  • 柴的断言
  • Sinon嘲弄/残留

所有这些工作都在node.js和浏览器中,这对包括我自己在内的许多人都很重要。 你可能会有很多select,虽然说到嘲笑和磕碰,我相信Sinon显然是目前stream行的select。

下面是使用所有这些库的coffeescript中的一个小例子。 它testing当你填写表格并提交时,你的信息被正确地传递给API。

describe "UserSignInView.signIn", -> it "should submit the user credentials", -> sinon.spy _OT.api, "sendJSON" testUser = email: "test.user@othenticate.com" password: "password" $("#OT_signInForm .OT_email").val(testUser.email).change() $("#OT_signInForm .OT_password").val(testUser.password).change() $("#OT_signInForm .OT_signInButton").click() assert.ok _OT.api.sendJSON.called credentials = _OT.api.sendJSON.lastCall.args[0] assert.equal credentials.email, testUser.email assert.equal credentials.password, testUser.password options = _OT.api.sendJSON.lastCall.args[1] assert.equal options.url, "/othen/users/authenticate" assert.isDefined options.error assert.isDefined options.success