aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2012-06-11 13:59:34 +0200
committerjaubourg <j@ubourg.net>2012-06-11 14:00:16 +0200
commitac48a19b92e60f08e5b00a46b5551a503c292fd5 (patch)
tree623962004549610b85a82740baf056633427e9a1 /test/unit
parent5f35b3d9f90d07ee084d59702a54051ee51fb0d3 (diff)
downloadjquery-ac48a19b92e60f08e5b00a46b5551a503c292fd5.tar.gz
jquery-ac48a19b92e60f08e5b00a46b5551a503c292fd5.zip
Some work to modularize ajax later on.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/ajax.js2
-rw-r--r--test/unit/attributes.js28
-rw-r--r--test/unit/core.js34
-rw-r--r--test/unit/manipulation.js14
-rw-r--r--test/unit/support.js67
5 files changed, 64 insertions, 81 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 878b311eb..b7e2cf191 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1,6 +1,6 @@
module("ajax", { teardown: moduleTeardown });
-if ( !isLocal || hasPHP) {
+if ( jQuery.ajax && ( !isLocal || hasPHP ) ) {
test("jQuery.ajax() - success callbacks", function() {
expect( 8 );
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index 6062bc7c9..d07ed85c9 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -683,7 +683,7 @@ test("removeProp(String)", function() {
});
test("val()", function() {
- expect(26);
+ expect( 20 + ( jQuery.fn.serialize ? 6 : 0 ) );
document.getElementById("text1").value = "bla";
equal( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
@@ -726,25 +726,27 @@ test("val()", function() {
jQuery("#select5").val(3);
equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
- var checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form");
+ if ( jQuery.fn.serialize ) {
+ var checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form");
- deepEqual( checks.serialize(), "", "Get unchecked values." );
+ deepEqual( checks.serialize(), "", "Get unchecked values." );
- equal( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
+ equal( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
- checks.val([ "2" ]);
- deepEqual( checks.serialize(), "test=2", "Get a single checked value." );
+ checks.val([ "2" ]);
+ deepEqual( checks.serialize(), "test=2", "Get a single checked value." );
- checks.val([ "1", "" ]);
- deepEqual( checks.serialize(), "test=1&test=", "Get multiple checked values." );
+ checks.val([ "1", "" ]);
+ deepEqual( checks.serialize(), "test=1&test=", "Get multiple checked values." );
- checks.val([ "", "2" ]);
- deepEqual( checks.serialize(), "test=2&test=", "Get multiple checked values." );
+ checks.val([ "", "2" ]);
+ deepEqual( checks.serialize(), "test=2&test=", "Get multiple checked values." );
- checks.val([ "1", "on" ]);
- deepEqual( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
+ checks.val([ "1", "on" ]);
+ deepEqual( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
- checks.remove();
+ checks.remove();
+ }
var $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button");
equal( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" );
diff --git a/test/unit/core.js b/test/unit/core.js
index 88c470104..9950228e8 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -236,26 +236,26 @@ test( "globalEval", function() {
window.globalEvalTest = undefined;
});
-if ( !isLocal ) {
-test("browser", function() {
- stop();
+if ( jQuery.get && !isLocal ) {
+ test("browser", function() {
+ stop();
+
+ jQuery.get("data/ua.txt", function(data){
+ var uas = data.split("\n");
+ expect( (uas.length - 1) * 2 );
+
+ jQuery.each(uas, function(){
+ var parts = this.split("\t");
+ if ( parts[2] ) {
+ var ua = jQuery.uaMatch( parts[2] );
+ equal( ua.browser, parts[0], "Checking browser for " + parts[2] );
+ equal( ua.version, parts[1], "Checking version string for " + parts[2] );
+ }
+ });
- jQuery.get("data/ua.txt", function(data){
- var uas = data.split("\n");
- expect( (uas.length - 1) * 2 );
-
- jQuery.each(uas, function(){
- var parts = this.split("\t");
- if ( parts[2] ) {
- var ua = jQuery.uaMatch( parts[2] );
- equal( ua.browser, parts[0], "Checking browser for " + parts[2] );
- equal( ua.version, parts[1], "Checking version string for " + parts[2] );
- }
+ start();
});
-
- start();
});
-});
}
test("noConflict", function() {
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index e8c183f3c..5ef64ed54 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -626,7 +626,7 @@ test("append(xml)", function() {
});
test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
- expect(17);
+ expect( 16 + ( jQuery.getScript ? 1 : 0 ) );
var defaultText = "Try them out:"
jQuery("<b>buga</b>").appendTo("#first");
@@ -699,11 +699,13 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
QUnit.reset();
- stop();
- jQuery.getScript('data/test.js', function() {
- jQuery('script[src*="data\\/test\\.js"]').remove();
- start();
- });
+ if ( jQuery.getScript ) {
+ stop();
+ jQuery.getScript('data/test.js', function() {
+ jQuery('script[src*="data\\/test\\.js"]').remove();
+ start();
+ });
+ }
});
var testPrepend = function(val) {
diff --git a/test/unit/support.js b/test/unit/support.js
index e733d520d..46ac22242 100644
--- a/test/unit/support.js
+++ b/test/unit/support.js
@@ -38,13 +38,14 @@ testIframeWithCallback( "A background on the testElement does not cause IE8 to c
ok( true, "IE8 does not crash" );
});
-var userAgent = window.navigator.userAgent;
+(function() {
-// These tests do not have to stay
-// They are here to help with upcoming support changes for 1.8
-if ( /chrome\/19\.0/i.test(userAgent) ) {
- test("Verify that the support tests resolve as expected per browser", function() {
- var i,
+ var userAgent = window.navigator.userAgent,
+ expected;
+
+ // These tests do not have to stay
+ // They are here to help with upcoming support changes for 1.8
+ if ( /chrome\/19\.0/i.test(userAgent) ) {
expected = {
"leadingWhitespace":true,
"tbody":true,
@@ -77,13 +78,7 @@ if ( /chrome\/19\.0/i.test(userAgent) ) {
"cors":true,
"doesNotIncludeMarginInBodyOffset":true
};
- for ( i in expected ) {
- equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
- }
- });
-} else if ( /msie 8\.0/i.test(userAgent) ) {
- test("Verify that the support tests resolve as expected per browser", function() {
- var i,
+ } else if ( /msie 8\.0/i.test(userAgent) ) {
expected = {
"leadingWhitespace":false,
"tbody":true,
@@ -116,13 +111,7 @@ if ( /chrome\/19\.0/i.test(userAgent) ) {
"cors":false,
"doesNotIncludeMarginInBodyOffset":true
};
- for ( i in expected ) {
- equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
- }
- });
-} else if ( /msie 7\.0/i.test(userAgent) ) {
- test("Verify that the support tests resolve as expected per browser", function() {
- var i,
+ } else if ( /msie 7\.0/i.test(userAgent) ) {
expected = {
"ajax": true,
"appendChecked": false,
@@ -155,13 +144,7 @@ if ( /chrome\/19\.0/i.test(userAgent) ) {
"tbody": false,
"style": false
};
- for ( i in expected ) {
- equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
- }
- });
-} else if ( /msie 6\.0/i.test(userAgent) ) {
- test("Verify that the support tests resolve as expected per browser", function() {
- var i,
+ } else if ( /msie 6\.0/i.test(userAgent) ) {
expected = {
"leadingWhitespace":false,
"tbody":false,
@@ -194,13 +177,7 @@ if ( /chrome\/19\.0/i.test(userAgent) ) {
"cors":false,
"doesNotIncludeMarginInBodyOffset":true
};
- for ( i in expected ) {
- equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
- }
- });
-} else if ( /5\.1\.1 safari/i.test(userAgent) ) {
- test("Verify that the support tests resolve as expected per browser", function() {
- var i,
+ } else if ( /5\.1\.1 safari/i.test(userAgent) ) {
expected = {
"leadingWhitespace":true,
"tbody":true,
@@ -233,13 +210,7 @@ if ( /chrome\/19\.0/i.test(userAgent) ) {
"cors":true,
"doesNotIncludeMarginInBodyOffset":true
};
- for ( i in expected ) {
- equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
- }
- });
-} else if ( /firefox\/3\.6/i.test(userAgent) ) {
- test("Verify that the support tests resolve as expected per browser", function() {
- var i,
+ } else if ( /firefox\/3\.6/i.test(userAgent) ) {
expected = {
"leadingWhitespace":true,
"tbody":true,
@@ -272,8 +243,16 @@ if ( /chrome\/19\.0/i.test(userAgent) ) {
"cors":true,
"doesNotIncludeMarginInBodyOffset":true
};
- for ( i in expected ) {
- equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
+ }
+
+ test("Verify that the support tests resolve as expected per browser", function() {
+ for ( var i in expected ) {
+ if ( jQuery.isAjax || i !== "ajax" && i !== "cors" ) {
+ equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
+ }
}
});
-}
+
+})();
+
+