From afb05081c013bdd38e0dc8ac1c99bbb9f5a00559 Mon Sep 17 00:00:00 2001 From: Ariel Flesler Date: Sat, 10 Jan 2009 00:16:48 +0000 Subject: [PATCH] testrunner: Putting back the global variables used for ajax tests. I added many calls to delete though. The global namespace must be cleaned up before calling start() again. --- test/data/test.html | 2 +- test/data/test.js | 2 +- test/data/test.php | 2 +- test/data/test2.html | 2 +- test/unit/ajax.js | 68 ++++++++++++++++++++++++++++++++++---------------- test/unit/fx.js | 8 +++--- 6 files changed, 54 insertions(+), 30 deletions(-) diff --git a/test/data/test.html b/test/data/test.html index b7c74c8..eec028e 100644 --- a/test/data/test.html +++ b/test/data/test.html @@ -1,6 +1,6 @@ html text
diff --git a/test/data/test.js b/test/data/test.js index 98e76de..403d0d4 100644 --- a/test/data/test.js +++ b/test/data/test.js @@ -1,3 +1,3 @@ -jQuery.foobar = "bar"; +foobar = "bar"; jQuery('#ap').html('bar'); ok( true, "test.js executed"); diff --git a/test/data/test.php b/test/data/test.php index bb392f1..3d08f32 100644 --- a/test/data/test.php +++ b/test/data/test.php @@ -1,6 +1,6 @@ html text
diff --git a/test/data/test2.html b/test/data/test2.html index 363c6de..dec2b5d 100644 --- a/test/data/test2.html +++ b/test/data/test2.html @@ -1,5 +1,5 @@ diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 357c536..2fafcae 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -161,13 +161,18 @@ test("jQuery.ajax - dataType html", function() { expect(5); stop(); - jQuery.foobar = null; - jQuery.testFoo = undefined; + window.foobar = null; + window.testFoo = undefined; var verifyEvaluation = function() { - equals( jQuery.testFoo, "foo", 'Check if script was evaluated for datatype html' ); - equals( jQuery.foobar, "bar", 'Check if script src was evaluated for datatype html' ); - start(); + equals( testFoo, "foo", 'Check if script was evaluated for datatype html' ); + equals( foobar, "bar", 'Check if script src was evaluated for datatype html' ); + + // Cleanup the global namespace + delete window.foobar; + delete window.testFoo; + + start(); }; jQuery.ajax({ @@ -243,18 +248,20 @@ test("pass-through request object", function() { var target = "data/name.html"; var successCount = 0; var errorCount = 0; - var errorEx = ""; + var errorEx = ""; var success = function() { successCount++; }; jQuery("#foo").ajaxError(function (e, xml, s, ex) { errorCount++; - errorEx += ": " + xml.status; + errorEx += ": " + xml.status; }); jQuery("#foo").one('ajaxStop', function () { equals(successCount, 5, "Check all ajax calls successful"); equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")"); jQuery("#foo").unbind('ajaxError'); + + delete window.foobar; start(); }); @@ -357,17 +364,24 @@ test("load(String, Function) - simple: inject text into DOM", function() { test("load(String, Function) - check scripts", function() { expect(7); stop(); - jQuery.testFoo = undefined; - jQuery.foobar = null; + + window.testFoo = undefined; + window.foobar = null; + var verifyEvaluation = function() { - equals( jQuery.foobar, "bar", 'Check if script src was evaluated after load' ); + equals( foobar, "bar", 'Check if script src was evaluated after load' ); equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM'); + + // Cleanup the global namespace + delete window.foobar; + delete window.testFoo; + start(); }; jQuery('#first').load(url('data/test.html'), function() { ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' ); equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); - equals( jQuery.testFoo, "foo", 'Check if script was evaluated after load' ); + equals( testFoo, "foo", 'Check if script was evaluated after load' ); setTimeout(verifyEvaluation, 600); }); }); @@ -375,10 +389,13 @@ test("load(String, Function) - check scripts", function() { test("load(String, Function) - check file with only a script tag", function() { expect(3); stop(); - jQuery.testFoo = undefined; + window.testFoo = undefined; jQuery('#first').load(url('data/test2.html'), function() { equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); - equals( jQuery.testFoo, "foo", 'Check if script was evaluated after load' ); + equals( testFoo, "foo", 'Check if script was evaluated after load' ); + + // Cleanup the global namespace + delete window.testFoo; start(); }); }); @@ -424,9 +441,10 @@ test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", f test("jQuery.getScript(String, Function) - with callback", function() { expect(2); stop(); - jQuery.foobar = null; + window.foobar = null; jQuery.getScript(url("data/test.js"), function() { - equals( jQuery.foobar, "bar", 'Check if script was evaluated' ); + equals( foobar, "bar", 'Check if script was evaluated' ); + delete window.foobar; setTimeout(start, 100); }); }); @@ -434,7 +452,10 @@ test("jQuery.getScript(String, Function) - with callback", function() { test("jQuery.getScript(String, Function) - no callback", function() { expect(1); stop(); - jQuery.getScript(url("data/test.js"), start); + jQuery.getScript(url("data/test.js"), function(){ + delete window.foobar; + start(); + }); }); test("jQuery.ajax() - JSONP, Local", function() { @@ -616,12 +637,13 @@ test("jQuery.ajax() - script, Remote", function() { stop(); - jQuery.foobar = null; + window.foobar = null; jQuery.ajax({ url: base + "data/test.js", dataType: "script", success: function(data){ - ok( jQuery.foobar, "Script results returned (GET, no callback)" ); + ok( foobar, "Script results returned (GET, no callback)" ); + delete window.foobar; start(); } }); @@ -634,14 +656,15 @@ test("jQuery.ajax() - script, Remote with POST", function() { stop(); - jQuery.foobar = null; + window.foobar = null; jQuery.ajax({ url: base + "data/test.js", type: "POST", dataType: "script", success: function(data, status){ - ok( jQuery.foobar, "Script results returned (GET, no callback)" ); + ok( foobar, "Script results returned (GET, no callback)" ); equals( status, "success", "Script results returned (GET, no callback)" ); + delete window.foobar; start(); } }); @@ -655,12 +678,13 @@ test("jQuery.ajax() - script, Remote with scheme-less URL", function() { stop(); - jQuery.foobar = null; + window.foobar = null; jQuery.ajax({ url: base + "data/test.js", dataType: "script", success: function(data){ - ok( jQuery.foobar, "Script results returned (GET, no callback)" ); + ok( foobar, "Script results returned (GET, no callback)" ); + delete window.foobar; start(); } }); diff --git a/test/unit/fx.js b/test/unit/fx.js index d53f77a..6de4254 100644 --- a/test/unit/fx.js +++ b/test/unit/fx.js @@ -337,15 +337,15 @@ jQuery.each( { }); }); -jQuery.check = ['opacity','height','width','display','overflow']; - jQuery.fn.saveState = function(){ - expect(jQuery.check.length); + var check = ['opacity','height','width','display','overflow']; + expect(check.length); + stop(); return this.each(function(){ var self = this; self.save = {}; - jQuery.each(jQuery.check, function(i,c){ + jQuery.each(check, function(i,c){ self.save[c] = jQuery.css(self,c); }); }); -- 1.7.10.4