我感到非常困惑,如何在mocha中进行涉及mongodb的单元测试,我仍然无法成功调用save函数而不抛出异常。
我尝试使用最简单的示例进行测试,并发现仍然存在问题。以下是我的代码。
var assert = require("assert")
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/dev', function(err){
if(err) throw err
});
describe('increment Id', function(){
describe('increment', function(){
it('should has increment', function(){
var Cat = mongoose.model('Cat', { name: String });
var kitty = new Cat({ name: 'Zildjian' });
kitty.save(function (err) {
if (err) throw err
console.log('meow');
});
})
})
})
这段代码并不会抛出异常,但是在mongodb中没有数据被更新或创建。
> show collections
pieces
sequences
system.indexes