I’ve been trying to learn how to use expresso for unit testing and am stumped on getting results from asynchronous mongoose database calls. It seems like the test does not wait around for the asynchronous calls to return so my asserts always fail.
"get tasks" : (beforeExit, assert) ->
tasks = null
Task.find {}, (err, result) ->
if not err
console.log 'results'
tasks = result
else
console.log 'error' + err
should.not(err)
beforeExit ->
tasks.should.not(null)
It seems like it might be hanging on the mongoose connect call as well
db = mongoose.connect config.connStr
so figured out the couple of things that were causing this to bonk out. My first mistake was not calling mongoose.disconnect() on teardown/beforeexit, and I should call mongoose.connect in a setup function. Another problem I had was that my test could not get a resonse from a mongoose model query Task.find {} if I had a require reference to a model file that was not in the same parent directory.
so keeping the test file in root parent directory caused Task.find {} to hang even though the reference was correct
but if I moved the test file up into the services folder, it mysteriously worked, not sure why