module("core"); test( "jQuery(html, props)", function() { expect( 3 ); var $el = jQuery( "", { name: "name", val: "value", size: 42 } ); equal( $el.attr("name"), "name", "Name attribute" ); equal( $el.attr("size"), jQuery.isEmptyObject(jQuery.attrFn) ? undefined : "42", "Size attribute" ); equal( $el.val(), "value", "Call setter method" ); }); test( "jQuery(html) loose rules", function() { expect( 33 ); var w, nowarns = { "simple tag": "
", "single tag with properties": "", "embedded newlines": "
very\nspacey\n like\n
text
", "embedded hash": "

love potion #9

", "complex html": "

hello !

", "leading space": "
", "leading newline": "\n
", "lots of space/newline": " spaces \n and \n newlines \n " }, warns = { "leading text": "don't
try this
", "trailing text": "
try this
junk", "both text": "don't
try this
either" }, generate = function( html ) { return function() { var el = jQuery( html ); equal( el.length, 1, html + " succeeded" ); equal( el.parent().length, 0, html + " generated new content" ); }; }; for ( w in nowarns ) { expectNoWarning( w, generate( nowarns[w] ) ); } for ( w in warns ) { expectWarning( w, generate( warns[w] ) ); } }); test( "jQuery( '#' )", function() { expect( 2 ); expectWarning( "Selector, through the jQuery constructor, nothing but hash", function() { var set = jQuery( "#" ); equal( set.length, 0, "empty set" ); }); }); test( "selector state", function() { expect( 18 ); var test; test = jQuery( undefined ); equal( test.selector, "", "Empty jQuery Selector" ); equal( test.context, undefined, "Empty jQuery Context" ); test = jQuery( document ); equal( test.selector, "", "Document Selector" ); equal( test.context, document, "Document Context" ); test = jQuery( document.body ); equal( test.selector, "", "Body Selector" ); equal( test.context, document.body, "Body Context" ); test = jQuery("#qunit-fixture"); equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); equal( test.context, document, "#qunit-fixture Context" ); test = jQuery("#notfoundnono"); equal( test.selector, "#notfoundnono", "#notfoundnono Selector" ); equal( test.context, document, "#notfoundnono Context" ); test = jQuery( "#qunit-fixture", document ); equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); equal( test.context, document, "#qunit-fixture Context" ); test = jQuery( "#qunit-fixture", document.body ); equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); equal( test.context, document.body, "#qunit-fixture Context" ); // Test cloning test = jQuery( test ); equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); equal( test.context, document.body, "#qunit-fixture Context" ); test = jQuery( document.body ).find("#qunit-fixture"); equal( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" ); equal( test.context, document.body, "#qunit-fixture find Context" ); }); test( "XSS injection", function() { expect( 10 ); // Bad HTML will throw on some supported versions expectWarning( "leading hash", function() { try { jQuery("#yeah

RIGHT

"); } catch ( e ) {} }); // Don't expect HTML if there's a leading hash char; this is // more strict than the 1.7 version but closes an XSS hole. expectWarning( "XSS via script tag", function() { var threw = false; window.XSS = false; try { jQuery( "#