Had to remove the global variable tricks (especially the delete window calls) as they cause

exceptions in IE. Also fixed a faulty test that assumed the order of Ajax function callbacks 
would be consistent.
This commit is contained in:
John Resig 2009-01-12 01:12:58 +00:00
parent 7623702565
commit aa29b8e3bc

View file

@ -157,21 +157,17 @@ test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" ); ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
}); });
window.foobar = null;
window.testFoo = undefined;
test("jQuery.ajax - dataType html", function() { test("jQuery.ajax - dataType html", function() {
expect(5); expect(5);
stop(); stop();
window.foobar = null;
window.testFoo = undefined;
var verifyEvaluation = function() { var verifyEvaluation = function() {
equals( testFoo, "foo", 'Check if script was evaluated for datatype html' ); equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
equals( foobar, "bar", 'Check if script src 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(); start();
}; };
@ -261,7 +257,6 @@ test("pass-through request object", function() {
equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")"); equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
jQuery("#foo").unbind('ajaxError'); jQuery("#foo").unbind('ajaxError');
delete window.foobar;
start(); start();
}); });
@ -365,17 +360,10 @@ test("load(String, Function) - check scripts", function() {
expect(7); expect(7);
stop(); stop();
window.testFoo = undefined;
window.foobar = null;
var verifyEvaluation = function() { var verifyEvaluation = function() {
equals( 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'); equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
// Cleanup the global namespace
delete window.foobar;
delete window.testFoo;
start(); start();
}; };
jQuery('#first').load(url('data/test.html'), function() { jQuery('#first').load(url('data/test.html'), function() {
@ -389,13 +377,11 @@ test("load(String, Function) - check scripts", function() {
test("load(String, Function) - check file with only a script tag", function() { test("load(String, Function) - check file with only a script tag", function() {
expect(3); expect(3);
stop(); stop();
window.testFoo = undefined;
jQuery('#first').load(url('data/test2.html'), function() { jQuery('#first').load(url('data/test2.html'), function() {
equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
equals( 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(); start();
}); });
}); });
@ -441,10 +427,8 @@ test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", f
test("jQuery.getScript(String, Function) - with callback", function() { test("jQuery.getScript(String, Function) - with callback", function() {
expect(2); expect(2);
stop(); stop();
window.foobar = null;
jQuery.getScript(url("data/test.js"), function() { jQuery.getScript(url("data/test.js"), function() {
equals( foobar, "bar", 'Check if script was evaluated' ); equals( foobar, "bar", 'Check if script was evaluated' );
delete window.foobar;
setTimeout(start, 100); setTimeout(start, 100);
}); });
}); });
@ -453,7 +437,6 @@ test("jQuery.getScript(String, Function) - no callback", function() {
expect(1); expect(1);
stop(); stop();
jQuery.getScript(url("data/test.js"), function(){ jQuery.getScript(url("data/test.js"), function(){
delete window.foobar;
start(); start();
}); });
}); });
@ -637,13 +620,11 @@ test("jQuery.ajax() - script, Remote", function() {
stop(); stop();
window.foobar = null;
jQuery.ajax({ jQuery.ajax({
url: base + "data/test.js", url: base + "data/test.js",
dataType: "script", dataType: "script",
success: function(data){ success: function(data){
ok( foobar, "Script results returned (GET, no callback)" ); ok( foobar, "Script results returned (GET, no callback)" );
delete window.foobar;
start(); start();
} }
}); });
@ -656,7 +637,6 @@ test("jQuery.ajax() - script, Remote with POST", function() {
stop(); stop();
window.foobar = null;
jQuery.ajax({ jQuery.ajax({
url: base + "data/test.js", url: base + "data/test.js",
type: "POST", type: "POST",
@ -664,7 +644,6 @@ test("jQuery.ajax() - script, Remote with POST", function() {
success: function(data, status){ success: function(data, status){
ok( foobar, "Script results returned (GET, no callback)" ); ok( foobar, "Script results returned (GET, no callback)" );
equals( status, "success", "Script results returned (GET, no callback)" ); equals( status, "success", "Script results returned (GET, no callback)" );
delete window.foobar;
start(); start();
} }
}); });
@ -678,13 +657,11 @@ test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
stop(); stop();
window.foobar = null;
jQuery.ajax({ jQuery.ajax({
url: base + "data/test.js", url: base + "data/test.js",
dataType: "script", dataType: "script",
success: function(data){ success: function(data){
ok( foobar, "Script results returned (GET, no callback)" ); ok( foobar, "Script results returned (GET, no callback)" );
delete window.foobar;
start(); start();
} }
}); });
@ -728,11 +705,14 @@ test("jQuery.getJSON(String, Function) - JSON object with absolute url to local
test("jQuery.post(String, Hash, Function) - simple with xml", function() { test("jQuery.post(String, Hash, Function) - simple with xml", function() {
expect(4); expect(4);
stop(); stop();
var done = 0;
jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){ jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
jQuery('math', xml).each(function() { jQuery('math', xml).each(function() {
equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' ); equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
equals( jQuery('result', this).text(), '3', 'Check for XML' ); equals( jQuery('result', this).text(), '3', 'Check for XML' );
}); });
if ( ++done === 2 ) start();
}); });
jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){ jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
@ -740,7 +720,7 @@ test("jQuery.post(String, Hash, Function) - simple with xml", function() {
equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' ); equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
equals( jQuery('result', this).text(), '3', 'Check for XML' ); equals( jQuery('result', this).text(), '3', 'Check for XML' );
}); });
start(); if ( ++done === 2 ) start();
}); });
}); });