Coding with a purpose

jQuery (QUnit): sharing variables between tests in different modules

18 December, 2008 · Leave a Comment

I went crazy for a few days trying to find out how to share variables between my tests in QUnit. If anybody knows of a better way, please share. This is an example of how to share the variable $phrases between two tests in two different modules:

$(document).ready(function () {
  //variables you want to share.
  var $phrases = $("#phrases li")

  module("Attributes:");
  test("trying out text():", function() {
    same($phrases.eq(0).text(), "myText");
  };
  module("Traversing:");
  test("trying out contents()", function() {
    same($phrases.eq(2).contents(), "<#text></#text>")
  };
});

Categories: Uncategorized

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment