Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe the methods, as outlined in the documentation, are as follows:</p> <ul> <li><code>spy.yield</code></li> <li><code>stub.yields</code></li> <li><code>stub.callsArg</code></li> </ul> <p>The main difference between <code>yields</code> and <code>callsArg</code> can be found in sinon's documentation for yields:</p> <blockquote> <p>If a method accepts more than one callback, you need to use callsArg to have the stub invoke other callbacks than the first one.</p> </blockquote> <p><code>yields</code> will call the <em>first</em> function argument it encounters with any optional arguments you provide to it. <code>callsArg</code> will attempt to invoke the function argument at the <em>given index</em> within that call's <code>arguments</code> object, and does not pass any arguments to it (you can use <code>callArgWith</code> for that behavior). </p> <p><code>spy.yield</code> is very similar to <code>stub.yields</code> except it is part of the spy API and it calls all callbacks passed to it. </p> <p>Here's some examples demonstrating the differences (forgive me if the examples are a bit contrived):</p> <p>Yields:</p> <pre><code>var fn = sinon.expectation.create().withArgs(1, 2); var stub = sinon.stub().yields(1, 2); stub(fn); fn.verify(); </code></pre> <p>CallsArg:</p> <pre><code>var f1 = sinon.expectation.create().never(); var f2 = sinon.expectation.create().once(); var stub = sinon.stub().callsArg(1); stub(f1, f2); f1.verify(); f2.verify(); </code></pre> <p>Yield:</p> <pre><code>var f1 = sinon.expectation.create().once(); var f2 = sinon.expectation.create().once(); var stub = sinon.stub().yield(); stub(f1, f2); f1.verify(); f2.verify(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload