【发布时间】:2014-10-12 07:28:04
【问题描述】:
感觉很迷茫,怎么单元测试涉及到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
【问题讨论】:
-
检查这个它可能是你问题的答案:) stackoverflow.com/questions/13320564/…
标签: node.js mongodb mongoose mocha.js