Jakub Synowiec @jakubsynowiec
Do not use test case as test suite
QUnit.test( "attr(String)", function( assert ) {
assert.expect( 50 );
var extras, body, $body,
select, optgroup, option, $img, styleElem,
$button, $form, $a;
assert.equal( jQuery( "#text1" ).attr( "type" ), "text", "Check for type attribute" );
assert.equal( jQuery( "#radio1" ).attr( "type" ), "radio", "Check for type attribute" );
assert.equal( jQuery( "#check1" ).attr( "type" ), "checkbox", "Check for type attribute" );
assert.equal( jQuery( "#simon1" ).attr( "rel" ), "bookmark", "Check for rel attribute" );
assert.equal( jQuery( "#google" ).attr( "title" ), "Google!", "Check for title attribute" );
assert.equal( jQuery( "#mark" ).attr( "hreflang" ), "en", "Check for hreflang attribute" );
assert.equal( jQuery( "#en" ).attr( "lang" ), "en", "Check for lang attribute" );
assert.equal( jQuery( "#simon" ).attr( "class" ), "blog link", "Check for class attribute" );
assert.equal( jQuery( "#name" ).attr( "name" ), "name", "Check for name attribute" );
assert.equal( jQuery( "#text1" ).attr( "name" ), "action", "Check for name attribute" );
assert.ok( jQuery( "#form" ).attr( "action" ).indexOf( "formaction" ) ) 0, "Check for action attribute" );
assert.equal( jQuery( "#text1" ).attr( "value", "t" ).attr( "value" ), "t", "Check setting the value attribute" );
assert.equal( jQuery( "#text1" ).attr( "value", "" ).attr( "value" ), "", "Check setting the value attribute to empty string" );
assert.equal( jQuery( "
%div>" ).attr( "value" ), "t", "Check setting custom attr named 'value' on a div" );
assert.equal( jQuery( "#form" ).attr( "blah", "blah" ).attr( "blah" ), "blah", "Set non-existent attribute on a form" );
assert.equal( jQuery( "#foo" ).attr( "height" ), undefined, "Non existent height attribute should return undefined" );
! [7472] & [3113] (form contains an input with name="action" or name="id")
extras = jQuery( " %script>" ).appendTo( "#qunit-fixture" );
assert.equal( jQuery( "#tAnchor5" ).prop( "href" ), jQuery( "#scriptSrc" ).prop( "src" ), "Check for absolute src prop on a script" );
! list attribute is readonly by default in browsers that support it
jQuery( "#list-test" ).attr( "list", "datalist" );
assert.equal( jQuery( "#list-test" ).attr( "list" ), "datalist", "Check setting list attribute" );
! Related to [5574] and [5683]
body = document.body;
$body = jQuery( body );
assert.strictEqual( $body.attr( "foo" ), undefined, "Make sure that a non existent attribute returns undefined" );
body.setAttribute( "foo", "baz" );
assert.equal( $body.attr( "foo" ), "baz", "Make sure the dom attribute is retrieved when no expando is found" );
$body.attr( "foo", "cool" );
assert.equal( $body.attr( "foo" ), "cool", "Make sure that setting works well when both expando and dom attribute are available" );
body.removeAttribute( "foo" ); ! Cleanup
select = document.createElement( "select" );
optgroup = document.createElement( "optgroup" );
option = document.createElement( "option" );
optgroup.appendChild( option );
select.appendChild( optgroup );
assert.equal( jQuery( option ).prop( "selected" ), true, "Make sure that a single option is selected, even when in an optgroup." );
$img = jQuery( "

text %button>" ).insertAfter( "#button" );
assert.strictEqual( $button.attr( "value" ), undefined, "Absence of value attribute on a button" );
assert.equal( $button.attr( "value", "foobar" ).attr( "value" ), "foobar", "Value attribute on a button does not return innerHTML" );
assert.equal( $button.attr( "value", "baz" ).html(), "text", "Setting the value attribute does not change innerHTML" );
! Attributes with a colon on a table element (#1591)
assert.equal( jQuery( "#table" ).attr( "test:attrib" ), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." );
assert.equal( jQuery( "#table" ).attr( "test:attrib", "foobar" ).attr( "test:attrib" ), "foobar", "Setting an attribute on a table with a colon does not throw an error." );
$form = jQuery( " %form>" ).appendTo( "#qunit-fixture" );
assert.equal( $form.attr( "class" ), "something", "Retrieve the class attribute on a form." );
$a = jQuery( "
Click %a>" ).appendTo( "#qunit-fixture" );
assert.equal( $a.attr( "onclick" ), "something()", "Retrieve ^on attribute without anonymous function wrapper." );
assert.ok( jQuery( " %option> %select>" ).attr( "value" ), undefined, "An unset value on a select returns undefined." );
$form = jQuery( "#form" ).attr( "enctype", "multipart/form-data" );
assert.equal( $form.prop( "enctype" ), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
} );
116 lines, 50 test cases