unit testing - How I could test jquery animate functions like fadeTo, fadeOut with js-test-driver? -


i tring write test cases js functions, facing irritating issue.

in script there code section like:

$("idofthediv").fadeout('fast'); 

or:

$("idofthediv").fadeto('fast', 1); 

which works fine on pages.

the problem came when had wanted write js-test-driver unit test cases. when want verify fadeto function:

...

asserttrue($("#idofthediv").css("opacity") == "0"); 

...

then fails.

the reason animation , when try verify, not finish animation.

could know way able test jquery animate functions in js-test-driver?

thanks! i'm looking forward answer. urgent issue me.

to test asynchronous behaviour need use asynctestcase js-test-driver.

try this:

fadetest = asynctestcase("fadetest", {  testfadeout : function(queue) {     // add html test     /*:doc += <div id="idofthediv"><p>foo</p></div>*/      var animationcomplete = false;      queue.call('prepare test', function(callbacks) {         var onanimationcomplete = callbacks.add(function() {             animationcomplete = true;         });          $("#idofthediv").fadeout('fast', onanimationcomplete);     });      // async test wait until onanimationcomplete function has been called.     // following part executed when animation done.     queue.call('assertion', function() {        asserttrue(animationcomplete);        // can check opacity of div        assertequals(0, $("#idofthediv").css("opacity"));      });  }  }); 

note: i haven't tried code myself. hope there no typos. ;)

edit: if function want test not have callback functionality can add using aop. procedure is:

  • add after() callback function want test (as in jsfiddle).
  • register after() function in callbacks object of queue.
  • in next queue-step can make assertions should true after method has completed.

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -