title: How to stub toJSON method created with Mongoose set() method
body: <p>I am looking for a way to stub the &quot;toJSON&quot; method.</p>
  <pre class="lang-js prettyprint-override"><code>ModelSchema.set(&quot;toJSON&quot;, {
    transform(doc, ret) {
      const { _id: id, __v, ...others } = ret;
      return { id, ...others };
    },
  });
  </code></pre>
  <p>I have tried doing.</p>
  <pre class="lang-js prettyprint-override"><code>sinon.stub(Modelname, &quot;toJSON&quot;)
  </code></pre>
  <p>But sinon throws an error saying</p>
  <pre><code>Cannot stub non-existent own property toJSON
  </code></pre>
  <p>Does anyone have any idea on how to stub this method, any help is greatly appreciated</p>