当 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);
});
});
});