JQuery Unit Testing tooltips (jasmine, qunit, etc..)

1.1k views Asked by At

I was wondering if anyone could provide me information, perhaps some example code, on how to unit test tooltips? The framework is no issue, I am free to use any kind of Javascript/JQuery framework there is available (Jasmine, Qunit etc). The hard part is that I can not really find a good example of how tooltips (which their scripts is called asynchronously) are tested.

So any example regarding unit testing JQuery UI tooltip or other external libraries (qtip etc) would be really helpfull.

2

There are 2 answers

9
Gary Storey On BEST ANSWER

The jQuery team uses Qunit for their testing. When I work on jQuery plugins, I tend to use the same tools. Here is an example test in Qunit:

//In your JS

function myTestFunction() {
  //code here
}

//In test.js

QUnit.test( 'My Tests: ', function( assert ) {

  'use strict';

  var $el = $('#my-tooltip');

  assert.strictEqual( typeof myFunction, 'function', 'It is a function.' );
  assert.notEqual( $el.css('display'), 'none', 'It is visible.' );

});
1
wrschneider On

Jasmine supports asynchronous tests in general. You can make your assertions in a callback and call done() to signify that your test successfully completed.

For example

it("should work with async", function(done) {
   doSomethingAsync().success(function() {
      // make assertions in callback
      done(); // done with test
   });
})