diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2012-12-08 16:28:10 -0500 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2012-12-14 10:37:20 -0500 |
commit | 2c40fdd4a852fe6ee16feaa3bb6d7d49c7a02606 (patch) | |
tree | b38e8ebf6f22bed3bb326f0398abce7c9a96905c /test | |
parent | 7d61c5238e57cf252faa2d999465bd69afc6c038 (diff) | |
download | jquery-2c40fdd4a852fe6ee16feaa3bb6d7d49c7a02606.tar.gz jquery-2c40fdd4a852fe6ee16feaa3bb6d7d49c7a02606.zip |
Fix #12600: don't use value property in place of value attribute. Close gh-1063.
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/attributes.js | 18 | ||||
-rw-r--r-- | test/unit/selector.js | 19 |
2 files changed, 26 insertions, 11 deletions
diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 4fb3f776e..943d096a8 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -54,7 +54,7 @@ test( "jQuery.propFix integrity test", function() { }); test( "attr(String)", function() { - expect( 48 ); + expect( 50 ); equal( jQuery("#text1").attr("type"), "text", "Check for type attribute" ); equal( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" ); @@ -68,6 +68,7 @@ test( "attr(String)", function() { equal( jQuery("#text1").attr("name"), "action", "Check for name attribute" ); ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" ); equal( jQuery("#text1").attr("value", "t").attr("value"), "t", "Check setting the value attribute" ); + equal( jQuery("#text1").attr("value", "").attr("value"), "", "Check setting the value attribute to empty string" ); equal( jQuery("<div value='t'></div>").attr("value"), "t", "Check setting custom attr named 'value' on a div" ); equal( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existant attribute on a form" ); equal( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" ); @@ -133,9 +134,10 @@ test( "attr(String)", function() { ok( !!~jQuery("#foo").attr("style", "position:absolute;").attr("style").indexOf("position"), "Check style setter" ); // Check value on button element (#1954) - var $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button"); - equal( $button.attr("value"), "foobar", "Value retrieval on a button does not return innerHTML" ); - equal( $button.attr("value", "baz").html(), "text", "Setting the value does not change innerHTML" ); + var $button = jQuery("<button>text</button>").insertAfter("#button"); + strictEqual( $button.attr("value"), undefined, "Absence of value attribute on a button" ); + equal( $button.attr( "value", "foobar" ).attr("value"), "foobar", "Value attribute on a button does not return innerHTML" ); + equal( $button.attr("value", "baz").html(), "text", "Setting the value attribute does not change innerHTML" ); // Attributes with a colon on a table element (#1591) equal( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." ); @@ -152,7 +154,7 @@ test( "attr(String)", function() { equal( jQuery("<div/>").attr( "title", "something" ).attr("title"), "something", "Set the title attribute." ); ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); equal( jQuery("<div/>").attr("value"), undefined, "An unset value on a div returns undefined." ); - equal( jQuery("<input/>").attr("value"), "", "An unset value on an input returns current value." ); + strictEqual( jQuery("<select><option value='property'></option></select>").attr("value"), undefined, "An unset value on a select returns undefined." ); $form = jQuery("#form").attr( "enctype", "multipart/form-data" ); equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" ); @@ -196,7 +198,7 @@ test( "attr(String, Function)", function() { equal( jQuery("#text1").attr( "value", function() { return this.id; - })[0].value, + }).attr("value"), "text1", "Set value from id" ); @@ -228,7 +230,7 @@ test( "attr(Hash)", function() { jQuery("#text1").attr({ "value": function() { return this["id"]; - }})[0].value, + }}).attr("value"), "text1", "Set attribute to computed value #1" ); @@ -384,7 +386,7 @@ test( "attr(String, Object)", function() { table.attr("cellspacing", "2"); equal( table[ 0 ]["cellSpacing"], "2", "Check cellspacing is correctly set" ); - equal( jQuery("#area1").attr("value"), "foobar", "Value attribute retrieves the property for backwards compatibility." ); + equal( jQuery("#area1").attr("value"), undefined, "Value attribute is distinct from value property." ); // for #1070 jQuery("#name").attr( "someAttr", "0" ); diff --git a/test/unit/selector.js b/test/unit/selector.js index 57c32cf0d..799603012 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -31,15 +31,28 @@ test("class - jQuery only", function() { }); test("attributes - jQuery only", function() { - expect( 2 ); + expect( 4 ); t( "Find elements with a tabindex attribute", "[tabindex]", ["listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex"] ); - // jQuery #12523 + + // #12523 deepEqual( jQuery.find( "[title]", null, null, jQuery("#qunit-fixture a").get().concat( document.createTextNode("") ) ), q("google"), "Text nodes fail attribute tests without exception" ); + + // #12600 + ok( + jQuery("<select value='12600'><option value='option' selected='selected'></option><option value=''></option></select>") + .prop( "value", "option" ) + .is(":input[value='12600']"), + + ":input[value=foo] selects select by attribute" + ); + ok( jQuery("<input type='text' value='12600'/>").prop( "value", "option" ).is(":input[value='12600']"), + ":input[value=foo] selects text input by attribute" + ); }); if ( jQuery.css ) { @@ -74,7 +87,7 @@ test("disconnected nodes", function() { equal( $opt.is(":selected"), true, "selected option" ); var $div = jQuery("<div/>"); - equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnect nodes." ); + equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." ); }); test("jQuery only - broken", 1, function() { |