• page

Getters & Assertions funcunit.getters

 

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 S 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.

S(".foo").visible(function(){
  // perform getters inside wait callbacks
  var size = S(".bar").size();
})

Assertions

To perform assertions, use QUnit assertion methods.

S(".foo").visible(function(){
  // perform assertions inside wait callbacks
  var size = S(".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(){
  S(".foo").click();
  // if this wait condition never becomes true, test will fail
  S(".bar").visible();
})

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

test("with assertions", function(){
  S(".expander").click()
    .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");
    })
})