javascript - QUnit fails tests inconsistently/alternately -


i have simplified qunit test consists of 2 simple tests fails randomly/alternately no reason (they both atomic, meaning 1 test doesn't change of other element)

please see this jsfiddle try run multiple times

module("basic actionbind"); //two simple tests test("action1", function() {     ok(ele2.trigger("click").hasclass("clicked"), "basic click action"); });  test("action2", function() {     ok(ele1.click().hasclass("clicked"), "basic click action"); }); 

the problem in caching of jquery objects in global context @ run-time. here's 2 snippets code (from link in question: http://jsfiddle.net/adardesign/azrk7/12/):

html:

<div id="qunit-fixture">     <span id="ele1" class="action" data-action="action1"></span>     <span id="ele2" class="action" data-action="action2" ></span> </div> 

js:

// caching elements var $ele1 = $('#ele1'),     $ele2 = $('#ele2');  test('action1', function() {     ok($ele2.trigger('click') ....   test('action2', function () {     ok($ele1.trigger('click') .... 

the actual elements inside #qunit-fixture reset , re-parsed each test, click events fired inside tests triggered on elements no longer in document. instead elements have been detached , #qunit-fixture has been re-parsed original html text, creating new dom elements.

i've forked jsfiddle , revised accordingly: http://jsfiddle.net/azrk7/15/

though cleaned various parts before noticed it, essential change moving query element inside test:

test('foo', function() {     var $foo = $('#ele1');     ok($foo.trigger('click') ....   test('bar', function () {     var $bar = $('#bar');     ok($bar.trigger('click') .... 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -