I am looking for a way to stub the "toJSON" method.
ModelSchema.set("toJSON", {
transform(doc, ret) {
const { _id: id, __v, ...others } = ret;
return { id, ...others };
},
});
I have tried doing.
sinon.stub(Modelname, "toJSON")
But sinon throws an error saying
Cannot stub non-existent own property toJSON
Does anyone have any idea on how to stub this method, any help is greatly appreciated