node.js - 使用 mocha 进行测试时,reSTLer 出现 "done() called multiple times"错误

标签 node.js coffeescript mocha.js

当我测试 ReSTLer 调用时,我收到了 did() 调用多次错误。如果我只让 ReSTLer 调用一次,它不会出错,但是如果我在一次测试运行中调用同一方法两次,它就会出错。

这是测试的简化版本

myModule = require 'myModule'

describe 'foo', ->
    describe 'bar', ->
        it "should hi", (done) ->
            myModule.hi done
        it "should hi again", (done) ->
            myModule.hi done

这是我的模块

rest = require 'restler'
exports.hi = (done) ->

    rest.get('http://google.com'
    ).on "complete", (data, response) ->
      console.log 'getting called once'             
      done null, data

我应该担心与 ReSTLer 的异步多个请求吗?是什么导致了这个错误?

添加时控制台日志输出

  ◦ should hi: getting called once
  ✓ should hi (221ms)
  ◦ should hi again: getting called once
  1) should hi
 getting called once
  ✓ should hi again (211ms)

最佳答案

看起来这是 ReSTLer 未更新以与 Node 0.10.x 兼容的问题

https://github.com/danwrong/restler/pull/113/files

ReSTLer 将多次调用回调,但有一个拉取请求可以修复该问题。

关于node.js - 使用 mocha 进行测试时,reSTLer 出现 "done() called multiple times"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17953585/

相关文章:

javascript - throttle 功能2秒

node.js - 我应该在嵌套的 Promise 上调用 .catch 吗?

javascript - 在不同浏览器上测试从对象中删除值时遇到的问题

node.js - 如何使用 sinon stub 异步数据库调用

Javascript:如何在回调中设置父对象变量

node.js - 如何使用html5和mysql在node.js中创建项目?

javascript - Angular 1 : How to wait for promise to resolve in parent controller?

javascript - Coffeescript 中的源映射 - 错误未映射到源

jquery - 如何使用 webdriverio、mocha 和 phantomjs 测试将字段设置为空字符串?

maven - 将 maven exec 插件正确绑定(bind)到测试阶段