我正在使用 coffeescript 编写一个节点应用程序,并使用 mocha.js 做一些 TDD。请有人指出我编写测试的正确方法。
我想做的: 'ra.do_get'的假响应然后调用方法'all_tests'来分析返回值
var RequestAdapter = require('./request_adapter');
class QueryHandler
constructor: (@adapter) ->
@klass = "QueryHandler"
@url = "http://localhost:#{port[@adapter]}/"
logger.debug "[#{@klass}] creating .."
//RequestAdapter is another class doing some GET/POST etc (using request NPM)
@ra = new RequestAdapter(@url)
all_tests: (cb) ->
logger.info "#{@adapter}: requesting all test - #{adapter_apis.ALL_TESTS_SESSION}"
_url = @url + adapter_apis.ALL_TESTS_SESSION
@ra.do_get _url, (error , response) ->
if error
return cb({error: true, message: "#{@adapter} adapter errored out"})
else
return cb(null,response)
return
谢谢