mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Enforce style guide in test/unit/attributes.js. Closes gh-985
This commit is contained in:
parent
45d64e8be1
commit
69ce829dfe
@ -1,7 +1,16 @@
|
||||
module("attributes", { teardown: moduleTeardown });
|
||||
module( "attributes", {
|
||||
teardown: moduleTeardown
|
||||
});
|
||||
|
||||
var bareObj = function( value ) { return value; };
|
||||
var functionReturningObj = function( value ) { return (function() { return value; }); };
|
||||
var bareObj = function( value ) {
|
||||
return value;
|
||||
};
|
||||
|
||||
var functionReturningObj = function( value ) {
|
||||
return (function() {
|
||||
return value;
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
======== local reference =======
|
||||
@ -78,7 +87,10 @@ test("attr(String)", function() {
|
||||
equal( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" );
|
||||
|
||||
// using innerHTML in IE causes href attribute to be serialized to the full path
|
||||
jQuery("<a/>").attr({ "id": "tAnchor5", "href": "#5" }).appendTo("#qunit-fixture");
|
||||
jQuery("<a/>").attr({
|
||||
"id": "tAnchor5",
|
||||
"href": "#5"
|
||||
}).appendTo("#qunit-fixture");
|
||||
equal( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" );
|
||||
|
||||
// list attribute is readonly by default in browsers that support it
|
||||
@ -98,7 +110,10 @@ test("attr(String)", function() {
|
||||
|
||||
body.removeAttribute("foo"); // Cleanup
|
||||
|
||||
var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option");
|
||||
var select = document.createElement("select"),
|
||||
optgroup = document.createElement("optgroup"),
|
||||
option = document.createElement("option");
|
||||
|
||||
optgroup.appendChild( option );
|
||||
select.appendChild( optgroup );
|
||||
|
||||
@ -148,21 +163,56 @@ test("attr(String) in XML Files", function() {
|
||||
|
||||
test( "attr(String, Function)", function() {
|
||||
expect( 2 );
|
||||
equal( jQuery("#text1").attr("value", function() { return this.id; })[0].value, "text1", "Set value from id" );
|
||||
equal( jQuery("#text1").attr("title", function(i) { return i; }).attr("title"), "0", "Set value with an index");
|
||||
|
||||
equal(
|
||||
jQuery("#text1").attr( "value", function() {
|
||||
return this.id;
|
||||
})[0].value,
|
||||
"text1",
|
||||
"Set value from id"
|
||||
);
|
||||
|
||||
equal(
|
||||
jQuery("#text1").attr( "title", function(i) {
|
||||
return i;
|
||||
}).attr("title"),
|
||||
"0",
|
||||
"Set value with an index"
|
||||
);
|
||||
});
|
||||
|
||||
test( "attr(Hash)", function() {
|
||||
expect( 3 );
|
||||
var pass = true;
|
||||
jQuery("div").attr({"foo": "baz", "zoo": "ping"}).each(function(){
|
||||
jQuery("div").attr({
|
||||
"foo": "baz",
|
||||
"zoo": "ping"
|
||||
}).each(function() {
|
||||
if ( this.getAttribute("foo") != "baz" && this.getAttribute("zoo") != "ping" ) {
|
||||
pass = false;
|
||||
}
|
||||
});
|
||||
|
||||
ok( pass, "Set Multiple Attributes" );
|
||||
equal( jQuery("#text1").attr({"value": function() { return this["id"]; }})[0].value, "text1", "Set attribute to computed value #1" );
|
||||
equal( jQuery("#text1").attr({"title": function(i) { return i; }}).attr("title"), "0", "Set attribute to computed value #2");
|
||||
|
||||
equal(
|
||||
jQuery("#text1").attr({
|
||||
"value": function() {
|
||||
return this["id"];
|
||||
}})[0].value,
|
||||
"text1",
|
||||
"Set attribute to computed value #1"
|
||||
);
|
||||
|
||||
equal(
|
||||
jQuery("#text1").attr({
|
||||
"title": function(i) {
|
||||
return i;
|
||||
}
|
||||
}).attr("title"),
|
||||
"0",
|
||||
"Set attribute to computed value #2"
|
||||
);
|
||||
});
|
||||
|
||||
test( "attr(String, Object)", function() {
|
||||
@ -180,13 +230,21 @@ test("attr(String, Object)", function() {
|
||||
|
||||
equal( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" );
|
||||
|
||||
ok( jQuery("#foo").attr({ "width": null }), "Try to set an attribute to nothing" );
|
||||
ok(
|
||||
jQuery("#foo").attr({
|
||||
"width": null
|
||||
}),
|
||||
"Try to set an attribute to nothing"
|
||||
);
|
||||
|
||||
jQuery("#name").attr( "name", "something" );
|
||||
equal( jQuery("#name").attr("name"), "something", "Set name attribute" );
|
||||
jQuery("#name").attr( "name", null );
|
||||
equal( jQuery("#name").attr("name"), undefined, "Remove name attribute" );
|
||||
var $input = jQuery("<input>", { name: "something", id: "specified" });
|
||||
var $input = jQuery( "<input>", {
|
||||
name: "something",
|
||||
id: "specified"
|
||||
});
|
||||
equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." );
|
||||
equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." );
|
||||
|
||||
@ -298,7 +356,7 @@ test("attr(String, Object)", function() {
|
||||
|
||||
// for #1070
|
||||
jQuery("#name").attr( "someAttr", "0" );
|
||||
equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to a string of \"0\"" );
|
||||
equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to a string of '0'" );
|
||||
jQuery("#name").attr( "someAttr", 0 );
|
||||
equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to the number 0" );
|
||||
jQuery("#name").attr( "someAttr", 1 );
|
||||
@ -352,7 +410,10 @@ test("attr(String, Object)", function() {
|
||||
ok( thrown, "Exception thrown when trying to change type property" );
|
||||
equal( "button", button.attr("type"), "Verify that you can't change the type of a button element" );
|
||||
|
||||
var $radio = jQuery("<input>", { "value": "sup", "type": "radio" }).appendTo("#testForm");
|
||||
var $radio = jQuery( "<input>", {
|
||||
"value": "sup",
|
||||
"type": "radio"
|
||||
}).appendTo("#testForm");
|
||||
equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" );
|
||||
|
||||
// Setting attributes on svg elements (bug #3116)
|
||||
@ -386,21 +447,31 @@ test("attr(jquery_method)", function(){
|
||||
|
||||
if ( jQuery.fn.offset ) {
|
||||
expected += 2;
|
||||
attrObj["offset"] = { "top": 1, "left": 0 };
|
||||
attrObj["offset"] = {
|
||||
"top": 1,
|
||||
"left": 0
|
||||
};
|
||||
}
|
||||
|
||||
if ( jQuery.css ) {
|
||||
expected += 3;
|
||||
attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 };
|
||||
attrObj["css"] = {
|
||||
"paddingLeft": 1,
|
||||
"paddingRight": 1
|
||||
};
|
||||
}
|
||||
|
||||
expect( expected );
|
||||
|
||||
// one at a time
|
||||
$elem.attr( { "html": "foo" }, true );
|
||||
$elem.attr({
|
||||
"html": "foo"
|
||||
}, true );
|
||||
equal( elem.innerHTML, "foo", "attr(html)" );
|
||||
|
||||
$elem.attr( { "text": "bar" }, true );
|
||||
$elem.attr({
|
||||
"text": "bar"
|
||||
}, true );
|
||||
equal( elem.innerHTML, "bar", "attr(text)" );
|
||||
|
||||
// Multiple attributes
|
||||
@ -409,14 +480,21 @@ test("attr(jquery_method)", function(){
|
||||
if ( jQuery.fn.width ) {
|
||||
equal( elem.style.width, "10px", "attr({width:})" );
|
||||
|
||||
$elem.attr( { "height": 10 }, true );
|
||||
$elem.attr( {
|
||||
"height": 10
|
||||
}, true );
|
||||
equal( elem.style.height, "10px", "attr(height)" );
|
||||
}
|
||||
|
||||
if ( jQuery.fn.offset ) {
|
||||
equal( elem.style.top, "1px", "attr({offset:})" );
|
||||
|
||||
$elem.attr( { offset: { top: 1, left: 1 } }, true );
|
||||
$elem.attr({
|
||||
offset: {
|
||||
top: 1,
|
||||
left: 1
|
||||
}
|
||||
}, true );
|
||||
equal( elem.style.left, "1px", "attr(offset)" );
|
||||
}
|
||||
|
||||
@ -424,7 +502,11 @@ test("attr(jquery_method)", function(){
|
||||
equal( elem.style.paddingLeft, "1px", "attr({css:})" );
|
||||
equal( elem.style.paddingRight, "1px", "attr({css:})" );
|
||||
|
||||
$elem.attr( { "css": { "color": "red" } }, true );
|
||||
$elem.attr({
|
||||
"css": {
|
||||
"color": "red"
|
||||
}
|
||||
}, true );
|
||||
ok( /^(#ff0000|red)$/i.test( elem.style.color ), "attr(css)" );
|
||||
}
|
||||
});
|
||||
@ -609,7 +691,10 @@ test("prop(String, Object)", function() {
|
||||
body["foo"] = undefined;
|
||||
ok( $body.prop("foo") === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" );
|
||||
|
||||
var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option");
|
||||
var select = document.createElement("select"),
|
||||
optgroup = document.createElement("optgroup"),
|
||||
option = document.createElement("option");
|
||||
|
||||
optgroup.appendChild( option );
|
||||
select.appendChild( optgroup );
|
||||
|
||||
@ -656,8 +741,8 @@ test("prop('tabindex')", function() {
|
||||
|
||||
test( "prop('tabindex', value)", 10, function() {
|
||||
|
||||
var element = jQuery("#divWithNoTabIndex"),
|
||||
clone;
|
||||
var clone,
|
||||
element = jQuery("#divWithNoTabIndex");
|
||||
|
||||
equal( element.prop("tabindex"), undefined, "start with no tabindex" );
|
||||
|
||||
@ -703,7 +788,11 @@ test("removeProp(String)", function() {
|
||||
textNode = document.createTextNode("some text"),
|
||||
obj = {};
|
||||
|
||||
strictEqual( jQuery( "#firstp" ).prop( "nonexisting", "foo" ).removeProp( "nonexisting" )[0]["nonexisting"], undefined, "removeprop works correctly on DOM element nodes" );
|
||||
strictEqual(
|
||||
jQuery( "#firstp" ).prop( "nonexisting", "foo" ).removeProp( "nonexisting" )[ 0 ]["nonexisting"],
|
||||
undefined,
|
||||
"removeprop works correctly on DOM element nodes"
|
||||
);
|
||||
|
||||
jQuery.each( [ document, obj ], function( i, ele ) {
|
||||
var $ele = jQuery( ele );
|
||||
@ -730,9 +819,9 @@ test("val()", function() {
|
||||
equal( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
|
||||
ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
|
||||
|
||||
equal( jQuery("#select2").val(), "3", "Call val() on a single=\"single\" select" );
|
||||
equal( jQuery("#select2").val(), "3", "Call val() on a single='single' select" );
|
||||
|
||||
deepEqual( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple=\"multiple\" select" );
|
||||
deepEqual( jQuery("#select3").val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" );
|
||||
|
||||
equal( jQuery("#option3c").val(), "2", "Call val() on a option element with value" );
|
||||
|
||||
@ -743,15 +832,15 @@ test("val()", function() {
|
||||
equal( jQuery("#option3a").val(), "", "Call val() on a option element with no value attribute" );
|
||||
|
||||
jQuery("#select3").val("");
|
||||
deepEqual( jQuery("#select3").val(), [""], "Call val() on a multiple=\"multiple\" select" );
|
||||
deepEqual( jQuery("#select3").val(), [""], "Call val() on a multiple='multiple' select" );
|
||||
|
||||
deepEqual( jQuery("#select4").val(), [], "Call val() on multiple=\"multiple\" select with all disabled options" );
|
||||
deepEqual( jQuery("#select4").val(), [], "Call val() on multiple='multiple' select with all disabled options" );
|
||||
|
||||
jQuery("#select4 optgroup").add("#select4 > [disabled]").attr( "disabled", false );
|
||||
deepEqual( jQuery("#select4").val(), ["2", "3"], "Call val() on multiple=\"multiple\" select with some disabled options" );
|
||||
deepEqual( jQuery("#select4").val(), [ "2", "3" ], "Call val() on multiple='multiple' select with some disabled options" );
|
||||
|
||||
jQuery("#select4").attr( "disabled", true );
|
||||
deepEqual( jQuery("#select4").val(), ["2", "3"], "Call val() on disabled multiple=\"multiple\" select" );
|
||||
deepEqual( jQuery("#select4").val(), [ "2", "3" ], "Call val() on disabled multiple='multiple' select" );
|
||||
|
||||
equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
|
||||
|
||||
@ -940,7 +1029,7 @@ test("val(select) after form.reset() (Bug #2551)", function() {
|
||||
equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." );
|
||||
|
||||
// re-verify the multi-select is not broken (after form.reset) by our fix for single-select
|
||||
deepEqual( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple=\"multiple\" select" );
|
||||
deepEqual( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple='multiple' select" );
|
||||
|
||||
jQuery("#kk").remove();
|
||||
});
|
||||
@ -1000,7 +1089,8 @@ test("addClass(Function)", function() {
|
||||
|
||||
test( "addClass(Function) with incoming value", function() {
|
||||
expect( 48 );
|
||||
var div = jQuery("div"), old = div.map(function(){
|
||||
var div = jQuery("div"),
|
||||
old = div.map(function() {
|
||||
return jQuery(this).attr("class") || "";
|
||||
});
|
||||
|
||||
@ -1266,8 +1356,8 @@ test("contents().hasClass() returns correct values", function() {
|
||||
test( "coords returns correct values in IE6/IE7, see #10828", function() {
|
||||
expect( 2 );
|
||||
|
||||
var map = jQuery("<map />"),
|
||||
area;
|
||||
var area,
|
||||
map = jQuery("<map />");
|
||||
|
||||
area = map.html("<area shape='rect' coords='0,0,0,0' href='#' alt='a' />").find("area");
|
||||
equal( area.attr("coords"), "0,0,0,0", "did not retrieve coords correctly" );
|
||||
|
Loading…
Reference in New Issue
Block a user