Showing posts with label nodeunit. Show all posts
Showing posts with label nodeunit. Show all posts

Jan 25, 2014

[Solved] NodeUnit does not finish when connected to Mongo DB

Posted Jan 25, 2014
When running NodeUnit tests and your tests are connected to Mongo DB, the tests do not end and it just hangs there. The fix is to close the connection on NodeUnit's tearDown function.

Example below is using Mongoose' disconnect function to close the connection after NodeUnit tests are done:
var mongoose = require('mongoose');
exports.tearDown = function(ok){
    mongoose.disconnect(function(err){
        if(err) {
            console.error(err);
            return;
        }
    });
    ok();
};