【发布时间】:2019-08-05 21:00:39
【问题描述】:
我正在尝试为我们使用猫鼬的应用程序编写单元测试。我在模型上有实例方法,调用 this.save()
例如。
MyModel.methods.update = function(data) {
this.param = data
this.save().then(updatedModel => {
return updatedModel
})
}
有没有办法存根 mongoose save 以返回当前的 this 对象?
基本上是这样的:
const save = sinon.stub(MyModel.prototype, 'save').resolves(this);
但这是实例方法中对 this 的引用。
希望我的描述是有道理的。任何帮助表示赞赏。 谢谢!
【问题讨论】:
标签: unit-testing testing mongoose mocha.js sinon