Getters & Assertions

  • page

Getter commands are jQuery getter methods. At certain points throughout a test, it's necessary to gather information about the page and perform assertions. Unlike FuncUnit API methods, getters
work synchronously.

Getter methods

Inside FuncUnit callbacks, the F method returns a jQuery collection. You can perform any jQuery getter method on it, like text, val, width, size, etc. Any jQuery method can be used as a getter.

  // perform getters inside wait callbacks
  var size = F(".bar").size();


To perform assertions, use QUnit assertion methods.

  // perform assertions inside wait callbacks
  var size = F(".bar").size();
  ok(size, 5, "there are 5 bars);

Tests without assertions

It's worth noting that it is possible to write entire tests without using any getters or assertions. Any wait condition will fail an assertion if they reach the timeout before succeeding.

Therefore, entire tests can be written with just action and wait methods. If the test succeeds, it will finish without any assertions. If it fails, it will throw a failed assertion.

test("test with waits", function(){
  // if this wait condition never becomes true, test will fail

Often, writing a test with assertions adds more unnecessary code.

test("with assertions", function(){
    .width(500, function(){
      // if the wait condition isn't met, this assertion won't run
      // therefore, this assertion isn't necessary
      ok(true, "expander is 500px");