Mongoose文件:手动执行钩子进行testing
我想testing一下在Mongoose pre
save
hook中执行的文档转换。 简单的例子:
mySchema.pre('save', function(callback) { this.property = this.property + '_modified'; callback(); });
testing:
var testDoc = new MyDocument({ property: 'foo' }); // TODO -- how to execute the hook? expect(testDoc.property).to.eql('foo_modified');
我怎样才能手动执行这个钩子?
好的,这是我们在最后做的。 我们使用no操作实现replace了$__save
函数:
// overwrite the $__save with a no op. function, // so that mongoose does not try to write to the database testDoc.$__save = function(options, callback) { callback(null, this); };
这样可以防止触击数据库,但是显然pre
钩仍然会被调用。
testDoc.save(function(err, doc) { expect(doc.property).to.eql('foo_modified'); done(); });
任务完成。
- 在IO.js 1.4.3中使用require()时Jest(JS)分段错误11
- 摩卡testing:“TypeError:undefined不是一个函数”在Test.serverAddress
- Aurelia e2e:text.indexOf()不正确地比较string和div中包含的string
- 如何在Node应用程序中编写Interswitch WebPAY集成testing?
- 我怎样才能有效地加载testing与无头浏览器的Web应用程序?
- 如何使用webpack手动testing反应组件?
- SailsJS Passport会话持久性问题:摩卡testing失败
- 如何自动testing我的webpack捆绑网站对付FUOC?
- 一个简单的Node.JS基准