如何在 nodeunit 和 mongoose 中获得异步结果?我试过下面的代码,它似乎挂在数据库回调上,从不返回结果或错误。
mongoose = require "mongoose"
models = require "../Services/models"
Task = models.Task
module.exports =
setUp: (callback) ->
try
@db = mongoose.connect "myConnString"
console.log 'Started connection, waiting for it to open'
@db.connection.on 'open', () ->
console.log 'Opened connection'
callback()
catch err
console.log 'Setting up failed:', err.message
tearDown: (callback) ->
console.log 'In tearDown'
try
console.log 'Closing connection'
@db.disconnect()
callback()
catch err
console.log 'Tearing down failed:', err.message
"get tasks" : (test) ->
console.log 'running first test'
Task.find {}, (err, result) ->
if not err
console.log 'results' + result
test.ok(result)
else
console.log 'error' + err
test.ifError(err)
test.done()