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

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")

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s