我正在使用factory girl在javascript中创建我的猫鼬模型实例。如何仅在测试环境中创建实例?
当我使用这个工厂时。这种方法使我的实例真正在MongoDB中。
Factory.create('User', {name: 'WES'}, function(user) {
// build a post and override title and content
// console.log(user)
});
Runnig测试后此实例在数据库中的持久性
User.find({ name: 'WES' }, 'name age', function (err, users) {
// if (err) return handleError(err);
console.log(users)
})
但是它必须仅在我的测试环境中。我必须在出厂后手动重置mongo DB还是可以自动设置?
我刚开始接触女工,但是我相信User.save()
正在被调用。运行测试后,尝试使用factory.create()
。factory.cleanUp()