摩卡芒果错误
mongoose试图连接到mongodb时,在我的摩卡testing中出现以下错误:
Error: Trying to open unclosed connection.
这是我的testing:
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); }); }); });
完成后closures连接:
after(function(done){ //clear out db User.remove(function(err){ Item.remove(function() { mongoose.connection.close(); done(); }); }); });
- 摩卡路线testing不是asynchronous执行的
- validation使用Mocha / Chai和asynchronous/等待引发exception
- Mocha MongoDB Mongoose ObjectId ref在第一个'it'语句后消失
- 在node.js服务器上读取supertest / superagent的响应输出缓冲区/stream
- 检测不需要的function(fdescribe,describe.only)作为Gulp任务
- 如何testing一个函数是否调用特定的方法/函数?
- nodemon应用程序崩溃时运行此“npm运行testing手表”
- unit testing使用Mongoose Promise的MongoDB查询
- zombie.js和Google Maps API