Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've modified @Ben's <a href="http://jsfiddle.net/Q8TDa/4/" rel="nofollow" title="fiddle">fiddle</a> to include your code with both of your tests. I modified some of your code to make it run correctly. When you hit the run button all of the tests will pass. When you hit the run button again, the second test ("alternately passing and failing") will fail -- this is basically simulating your original issue.</p> <p>The issue is your first test ("always passing test") <strong>alters the global state</strong> by replacing the <code>jQuery.fn.on</code> function with an overridden one. Because of this, when the tests are run in order, the second test ("alternately passing and failing") uses the incorrect overridden <code>jQuery.fn.on</code> function and fails. <em>Each unit test should return the global state back to its pre-test state so that other tests can run based on the same assumptions.</em></p> <p>The reason why it's alternating between pass and fail is that under the hood QUnit always runs failed tests first (it remembers this somehow via cookie or local storage, I'm not exactly sure). When it runs the failed tests first, the second test runs <em>before</em> the first one; as a result, the second test gets jQuery's native <code>on</code> function and works. When you run it a third time, the tests will run in their "original" order and the second test will use the overridden <code>on</code> function and fail.</p> <p>Here's the working <a href="http://jsfiddle.net/Q8TDa/5/" rel="nofollow" title="fiddle">fiddle</a>. I've add the fix to "un-override" the <code>on</code> function after the test by caching the original <code>var jQueryOn = jQuery.fn.on;</code> function and resetting it at the end of the test via: <code>jQuery.fn.on = jQueryOn;</code>. You can probably better implement this using QUnit's module <code>teardown()</code> method instead.</p> <p>You can check out <a href="https://github.com/jquery/qunit/issues/74" rel="nofollow">https://github.com/jquery/qunit/issues/74</a> for more info.</p>
    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