mongoose が mongodb に接続しようとすると、mocha テストで次のエラーが発生します。
Error: Trying to open unclosed connection.
これが私のテストです:
var cfg = require('../config')
, mongoose = require('mongoose')
, db = mongoose.connect(cfg.mongo.uri, cfg.mongo.db)
, User = require('../models/user')
, Item = require('../models/item')
, should = require('should')
, fakeUser
, fakeItem;
mongoose.connection.on('error', function(err){
console.log(err);
});
describe('User', function(){
beforeEach(function(done){
//clear out db
User.remove(done);
});
after(function(done){
//clear out db
User.remove(function(err){
Item.remove(done);
});
});
});