当我测试一个 restler 调用时,我收到了一个 done() 调用多次错误。如果我只让 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)