-
Type: Task
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.3
-
Component/s: None
-
Environment:mongoose 3.6.20 using mongodb 1.3.19
-
Empty show more show less
We've come across this issue several time in our unit tests: a failed assertion (or any other exception thrown) never reaches the Mocha/Node exception handlers, if it is caused/thrown within certain Mongoose callbacks.
Here's an example of a Mocha test that never returns:
—
mongoose = require('mongoose')
Model = mongoose.model('Model', new mongoose.Schema())
mongoose.connect('mongodb://localhost/database')
it('hanging test', (done) ->
Model.aggregate({}, () ->
- Simulating a failed assertion:
throw new Error('Some failed assertion')
done()
)
)
—
The exception is handled by Base.prototype._callHandler() and is never re-thrown again, so Mocha/Node (and before that Mongoose's utils.tick()) are unable to catch it.
This doesn't happen for all queries. If find() or create() are used above, the exception is first caught by Mongoose's utils.tick() and then re-thrown, so Mocha is able to handle them in the end.
Any thoughts on this?