[英]how to reset mongoose after using factory girl in test?
I'm using factory girl for creating my mongoose model instance in javascript.我正在使用工厂女孩在 javascript 中创建我的猫鼬模型实例。 how can I make-instance just in the test environment?
如何仅在测试环境中创建实例?
when I use this factory.当我使用这家工厂时。 this method makes my instance really in MongoDB.
这种方法使我的实例真正在 MongoDB 中。
Factory.create('User', {name: 'WES'}, function(user) {
// build a post and override title and content
// console.log(user)
});
this instance persistence in my DB after runnig test runnig 测试后,这个实例在我的数据库中持久化
User.find({ name: 'WES' }, 'name age', function (err, users) {
// if (err) return handleError(err);
console.log(users)
})
but it must be just in my test environment.但它必须只是在我的测试环境中。 I have to reset my mongo DB manually after factory or I can set it automatically?
我必须在出厂后手动重置我的 mongo DB 还是可以自动设置?
I'm just getting started with factory girl, but I believe User.save()
is getting called in factory.create()
.我刚刚开始接触工厂女孩,但我相信在
factory.create()
调用User.save()
factory.create()
。 Try using factory.cleanUp()
after running your tests.运行测试后尝试使用
factory.cleanUp()
。 See this github issue for more information.有关更多信息,请参阅此 github 问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.