1
我想模拟一个填充调用,我想模拟返回猫鼬对象,而不是普通的JS对象。填充调用后模拟鼬对象
sandbox.mock(BookModel)
.expects('populate')
.yields(null, [
new BookModel({
_id: mongoose.Types.ObjectId(),
name: 'Mock Book',
authorIds: [{
name: 'Foo',
}]
})
]);
随着模式:
var BookSchema = new Schema({
name: { type: String, required: true, unique: true },
authorIds: [{type: Schema.Types.ObjectId, ref: 'Author'}],
});
var AuthorSchema = new Schema({
name: { type: String, required: true, unique: true },
});
但是猫鼬是防止我的测试从使用模拟填充笔者猫鼬可能是检查的authorIds数组对象ID阵列,创建模拟对象。
有没有人使用sinon来嘲笑这样的人口稠密的领域?
工作,谢谢! – lostintranslation