当我测试 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/