2015-08-16 03:45:28 +00:00
QUnit . module ( "manipulation" , {
2019-02-18 18:02:38 +00:00
afterEach : moduleTeardown
2015-08-16 06:59:58 +00:00
} ) ;
2009-04-20 17:05:18 +00:00
2010-12-21 03:23:59 +00:00
// Ensure that an extended Array prototype doesn't break jQuery
2013-04-09 15:45:09 +00:00
Array . prototype . arrayProtoFn = function ( ) {
2012-12-04 18:21:47 +00:00
} ;
2010-12-21 03:23:59 +00:00
2013-04-09 15:45:09 +00:00
function manipulationBareObj ( value ) {
2012-12-04 18:21:47 +00:00
return value ;
2013-04-09 15:45:09 +00:00
}
2009-07-12 20:19:43 +00:00
2013-04-09 15:45:09 +00:00
function manipulationFunctionReturningObj ( value ) {
return function ( ) {
2012-12-04 18:21:47 +00:00
return value ;
2013-04-09 15:45:09 +00:00
} ;
}
2012-06-21 19:30:24 +00:00
2012-05-29 16:40:13 +00:00
/ *
=== === == local reference === === =
2012-07-05 19:52:13 +00:00
manipulationBareObj and manipulationFunctionReturningObj can be used to test passing functions to setters
2012-05-29 16:40:13 +00:00
See testVal below for an example
bareObj ( value ) ;
This function returns whatever value is passed in
functionReturningObj ( value ) ;
Returns a function that returns the value
* /
2015-08-16 03:45:28 +00:00
QUnit . test ( "text()" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 5 ) ;
2012-12-05 02:50:22 +00:00
2012-12-04 18:21:47 +00:00
var expected , frag , $newLineTest ;
expected = "This link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for merged text of more then one element." ) ;
2009-11-17 19:52:08 +00:00
// Check serialization of text values
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( document . createTextNode ( "foo" ) ) . text ( ) , "foo" , "Text node was retrieved from .text()." ) ;
assert . notEqual ( jQuery ( document ) . text ( ) , "" , "Retrieving text for the document retrieves all text (#10724)." ) ;
2012-01-20 21:47:49 +00:00
// Retrieve from document fragments #10864
2012-12-04 18:21:47 +00:00
frag = document . createDocumentFragment ( ) ;
2015-08-16 06:59:58 +00:00
frag . appendChild ( document . createTextNode ( "foo" ) ) ;
2012-01-20 21:47:49 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( frag ) . text ( ) , "foo" , "Document Fragment Text node was retrieved from .text()." ) ;
2012-03-30 21:09:46 +00:00
2015-08-16 06:59:58 +00:00
$newLineTest = jQuery ( "<div>test<br/>testy</div>" ) . appendTo ( "#moretests" ) ;
$newLineTest . find ( "br" ) . replaceWith ( "\n" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( $newLineTest . text ( ) , "test\ntesty" , "text() does not remove new lines (#11153)" ) ;
2012-07-02 15:30:22 +00:00
$newLineTest . remove ( ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "text(undefined)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#foo" ) . text ( "<div" ) . text ( undefined ) [ 0 ] . innerHTML , "<div" , ".text(undefined) is chainable (#5571)" ) ;
} ) ;
2011-12-06 20:25:38 +00:00
2015-08-16 03:45:28 +00:00
function testText ( valueObj , assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 6 ) ;
2012-12-05 02:50:22 +00:00
2013-10-30 08:16:05 +00:00
var val , j , expected , $multipleElements , $parentDiv , $childDiv ;
2012-12-04 18:21:47 +00:00
2015-08-16 06:59:58 +00:00
val = valueObj ( "<div><b>Hello</b> cruel world!</div>" ) ;
assert . equal ( jQuery ( "#foo" ) . text ( val ) [ 0 ] . innerHTML . replace ( />/g , ">" ) , "<div><b>Hello</b> cruel world!</div>" , "Check escaped text" ) ;
2010-01-07 16:51:48 +00:00
// using contents will get comments regular, text, and comment nodes
2015-08-16 06:59:58 +00:00
j = jQuery ( "#nonnodes" ) . contents ( ) ;
j . text ( valueObj ( "hi!" ) ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( jQuery ( j [ 0 ] ) . text ( ) , "hi!" , "Check node,textnode,comment with text()" ) ;
assert . equal ( j [ 1 ] . nodeValue , " there " , "Check node,textnode,comment with text()" ) ;
2010-08-26 19:36:44 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( j [ 2 ] . nodeType , 8 , "Check node,textnode,comment with text()" ) ;
2013-10-30 08:16:05 +00:00
// Update multiple elements #11809
expected = "New" ;
$multipleElements = jQuery ( "<div>Hello</div>" ) . add ( "<div>World</div>" ) ;
$multipleElements . text ( expected ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( $multipleElements . eq ( 0 ) . text ( ) , expected , "text() updates multiple elements (#11809)" ) ;
assert . equal ( $multipleElements . eq ( 1 ) . text ( ) , expected , "text() updates multiple elements (#11809)" ) ;
2013-10-30 08:16:05 +00:00
// Prevent memory leaks #11809
2020-03-16 20:49:29 +00:00
$childDiv = jQuery ( "<div></div>" ) ;
2015-08-16 06:59:58 +00:00
$childDiv . data ( "leak" , true ) ;
2020-03-16 20:49:29 +00:00
$parentDiv = jQuery ( "<div></div>" ) ;
2013-10-30 08:16:05 +00:00
$parentDiv . append ( $childDiv ) ;
2015-08-16 06:59:58 +00:00
$parentDiv . text ( "Dry off" ) ;
2013-04-09 15:45:09 +00:00
}
2010-01-07 16:51:48 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "text(String)" , function ( assert ) {
testText ( manipulationBareObj , assert ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2010-01-07 16:51:48 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "text(Function)" , function ( assert ) {
testText ( manipulationFunctionReturningObj , assert ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2010-01-07 16:51:48 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "text(Function) with incoming value" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2010-12-07 01:37:16 +00:00
2010-01-07 16:51:48 +00:00
var old = "This link has class=\"blog\": Simon Willison's Weblog" ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . text ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2010-01-07 16:51:48 +00:00
return "foobar" ;
2015-08-16 06:59:58 +00:00
} ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#sap" ) . text ( ) , "foobar" , "Check for merged text of more then one element." ) ;
} ) ;
2010-01-07 16:51:48 +00:00
2015-08-16 03:45:28 +00:00
function testAppendForObject ( valueObj , isFragment , assert ) {
2012-11-08 15:05:10 +00:00
var $base ,
type = isFragment ? " (DocumentFragment)" : " (Element)" ,
text = "This link has class=\"blog\": Simon Willison's Weblog" ,
2015-08-16 06:59:58 +00:00
el = document . getElementById ( "sap" ) . cloneNode ( true ) ,
first = document . getElementById ( "first" ) ,
yahoo = document . getElementById ( "yahoo" ) ;
2012-11-08 15:05:10 +00:00
if ( isFragment ) {
$base = document . createDocumentFragment ( ) ;
2015-08-16 06:59:58 +00:00
jQuery ( el ) . contents ( ) . each ( function ( ) {
2012-11-08 15:05:10 +00:00
$base . appendChild ( this ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-11-08 15:05:10 +00:00
$base = jQuery ( $base ) ;
} else {
$base = jQuery ( el ) ;
}
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $base . clone ( ) . append ( valueObj ( first . cloneNode ( true ) ) ) . text ( ) ,
2012-11-08 15:05:10 +00:00
text + "Try them out:" ,
"Check for appending of element" + type
) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $base . clone ( ) . append ( valueObj ( [ first . cloneNode ( true ) , yahoo . cloneNode ( true ) ] ) ) . text ( ) ,
2012-11-08 15:05:10 +00:00
text + "Try them out:Yahoo" ,
"Check for appending of array of elements" + type
) ;
2012-06-16 01:37:01 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $base . clone ( ) . append ( valueObj ( jQuery ( "#yahoo, #first" ) . clone ( ) ) ) . text ( ) ,
2012-11-08 15:05:10 +00:00
text + "YahooTry them out:" ,
"Check for appending of jQuery object" + type
) ;
2012-06-16 01:37:01 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( $base . clone ( ) . append ( valueObj ( 5 ) ) . text ( ) ,
2012-11-08 15:05:10 +00:00
text + "5" ,
"Check for appending a number" + type
) ;
2012-06-16 02:17:05 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $base . clone ( ) . append ( valueObj ( [ jQuery ( "#first" ) . clone ( ) , jQuery ( "#yahoo, #google" ) . clone ( ) ] ) ) . text ( ) ,
2012-11-08 15:05:10 +00:00
text + "Try them out:GoogleYahoo" ,
"Check for appending of array of jQuery objects"
) ;
2012-06-16 01:37:01 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $base . clone ( ) . append ( valueObj ( " text with spaces " ) ) . text ( ) ,
2012-11-08 15:05:10 +00:00
text + " text with spaces " ,
"Check for appending text with spaces" + type
) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $base . clone ( ) . append ( valueObj ( [ ] ) ) . text ( ) ,
2012-11-08 15:05:10 +00:00
text ,
"Check for appending an empty array" + type
) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $base . clone ( ) . append ( valueObj ( "" ) ) . text ( ) ,
2012-11-08 15:05:10 +00:00
text ,
"Check for appending an empty string" + type
) ;
2012-06-21 19:30:24 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $base . clone ( ) . append ( valueObj ( document . getElementsByTagName ( "foo" ) ) ) . text ( ) ,
2012-11-08 15:05:10 +00:00
text ,
"Check for appending an empty nodelist" + type
) ;
2012-06-16 01:37:01 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( $base . clone ( ) . append ( "<span></span>" , "<span></span>" , "<span></span>" ) . children ( ) . length ,
2012-11-08 15:05:10 +00:00
$base . children ( ) . length + 3 ,
"Make sure that multiple arguments works." + type
2012-06-16 01:37:01 +00:00
) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $base . clone ( ) . append ( valueObj ( document . getElementById ( "form" ) . cloneNode ( true ) ) ) . children ( "form" ) . length ,
2012-11-08 15:05:10 +00:00
1 ,
"Check for appending a form (#910)" + type
) ;
2013-04-09 15:45:09 +00:00
}
2012-06-16 01:37:01 +00:00
2015-08-16 03:45:28 +00:00
function testAppend ( valueObj , assert ) {
2012-12-05 02:50:22 +00:00
2019-06-26 19:39:10 +00:00
assert . expect ( 82 ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
testAppendForObject ( valueObj , false , assert ) ;
testAppendForObject ( valueObj , true , assert ) ;
2012-12-04 18:21:47 +00:00
var defaultText , result , message , iframe , iframeDoc , j , d ,
2012-12-28 15:43:01 +00:00
$input , $radioChecked , $radioUnchecked , $radioParent , $map , $table ;
2012-12-04 18:21:47 +00:00
defaultText = "Try them out:" ;
2015-08-16 06:59:58 +00:00
result = jQuery ( "#first" ) . append ( valueObj ( "<b>buga</b>" ) ) ;
2012-06-16 01:37:01 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( result . text ( ) , defaultText + "buga" , "Check if text appending works" ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#select3" ) . append ( valueObj ( "<option value='appendTest'>Append Test</option>" ) ) . find ( "option:last-child" ) . attr ( "value" ) , "appendTest" , "Appending html options to select element" ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture form" ) . append ( valueObj ( "<input name='radiotest' type='radio' checked='checked' />" ) ) ;
jQuery ( "#qunit-fixture form input[name=radiotest]" ) . each ( function ( ) {
assert . ok ( jQuery ( this ) . is ( ":checked" ) , "Append checked radio" ) ;
} ) . remove ( ) ;
2010-01-25 23:43:33 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture form" ) . append ( valueObj ( "<input name='radiotest2' type='radio' checked = 'checked' />" ) ) ;
jQuery ( "#qunit-fixture form input[name=radiotest2]" ) . each ( function ( ) {
2020-04-29 19:18:23 +00:00
assert . ok ( jQuery ( this ) . is ( ":checked" ) , "Append alternately formatted checked radio" ) ;
2015-08-16 06:59:58 +00:00
} ) . remove ( ) ;
2010-01-25 23:43:33 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture form" ) . append ( valueObj ( "<input name='radiotest3' type='radio' checked />" ) ) ;
jQuery ( "#qunit-fixture form input[name=radiotest3]" ) . each ( function ( ) {
2020-04-29 19:18:23 +00:00
assert . ok ( jQuery ( this ) . is ( ":checked" ) , "Append HTML5-formatted checked radio" ) ;
2015-08-16 06:59:58 +00:00
} ) . remove ( ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture form" ) . append ( valueObj ( "<input type='radio' checked='checked' name='radiotest4' />" ) ) ;
jQuery ( "#qunit-fixture form input[name=radiotest4]" ) . each ( function ( ) {
assert . ok ( jQuery ( this ) . is ( ":checked" ) , "Append with name attribute after checked attribute" ) ;
} ) . remove ( ) ;
2012-02-09 14:45:34 +00:00
2012-12-04 18:21:47 +00:00
message = "Test for appending a DOM node to the contents of an iframe" ;
2015-08-16 06:59:58 +00:00
iframe = jQuery ( "#iframe" ) [ 0 ] ;
2012-12-04 18:21:47 +00:00
iframeDoc = iframe . contentDocument || iframe . contentWindow && iframe . contentWindow . document ;
2009-03-18 21:15:38 +00:00
try {
2012-11-08 15:05:10 +00:00
if ( iframeDoc && iframeDoc . body ) {
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( iframeDoc . body ) . append ( valueObj ( "<div id='success'>test</div>" ) ) [ 0 ] . lastChild . id , "success" , message ) ;
2012-11-08 15:05:10 +00:00
} else {
2015-08-16 03:45:28 +00:00
assert . ok ( true , message + " - can't test" ) ;
2012-11-08 15:05:10 +00:00
}
2015-08-16 06:59:58 +00:00
} catch ( e ) {
2015-08-16 03:45:28 +00:00
assert . strictEqual ( e . message || e , undefined , message ) ;
2012-11-08 15:05:10 +00:00
}
2009-03-18 21:15:38 +00:00
2020-03-16 20:49:29 +00:00
jQuery ( "<fieldset></fieldset>" ) . appendTo ( "#form" ) . append ( valueObj ( "<legend id='legend'>test</legend>" ) ) ;
2015-09-08 00:26:29 +00:00
assert . t ( "Append legend" , "#legend" , [ "legend" ] ) ;
2009-03-18 21:15:38 +00:00
2020-03-16 20:49:29 +00:00
$map = jQuery ( "<map></map>" ) . append ( valueObj ( "<area id='map01' shape='rect' coords='50,50,150,150' href='https://www.jquery.com/' alt='jQuery'>" ) ) ;
2012-12-28 14:39:12 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( $map [ 0 ] . childNodes . length , 1 , "The area was inserted." ) ;
assert . equal ( $map [ 0 ] . firstChild . nodeName . toLowerCase ( ) , "area" , "The area was inserted." ) ;
2012-12-28 14:39:12 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#select1" ) . append ( valueObj ( "<OPTION>Test</OPTION>" ) ) ;
assert . equal ( jQuery ( "#select1 option:last-child" ) . text ( ) , "Test" , "Appending OPTION (all caps)" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#select1" ) . append ( valueObj ( "<optgroup label='optgroup'><option>optgroup</option></optgroup>" ) ) ;
assert . equal ( jQuery ( "#select1 optgroup" ) . attr ( "label" ) , "optgroup" , "Label attribute in newly inserted optgroup is correct" ) ;
assert . equal ( jQuery ( "#select1 option" ) . last ( ) . text ( ) , "optgroup" , "Appending optgroup" ) ;
2012-12-28 14:56:29 +00:00
2015-08-16 06:59:58 +00:00
$table = jQuery ( "#table" ) ;
2012-12-28 15:43:01 +00:00
2015-08-16 06:59:58 +00:00
jQuery . each ( "thead tbody tfoot colgroup caption tr th td" . split ( " " ) , function ( i , name ) {
2012-12-28 15:43:01 +00:00
$table . append ( valueObj ( "<" + name + "/>" ) ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( $table . find ( name ) . length , 1 , "Append " + name ) ;
assert . ok ( jQuery . parseHTML ( "<" + name + "/>" ) . length , name + " wrapped correctly" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-03-18 21:15:38 +00:00
2020-03-16 20:49:29 +00:00
jQuery ( "#table colgroup" ) . append ( valueObj ( "<col></col>" ) ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#table colgroup col" ) . length , 1 , "Append col" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#form" )
. append ( valueObj ( "<select id='appendSelect1'></select>" ) )
. append ( valueObj ( "<select id='appendSelect2'><option>Test</option></select>" ) ) ;
2015-09-08 00:26:29 +00:00
assert . t ( "Append Select" , "#appendSelect1, #appendSelect2" , [ "appendSelect1" , "appendSelect2" ] ) ;
2009-03-18 21:15:38 +00:00
2020-03-16 20:49:29 +00:00
assert . equal ( "Two nodes" , jQuery ( "<div></div>" ) . append ( "Two" , " nodes" ) . text ( ) , "Appending two text nodes (#4011)" ) ;
assert . equal ( jQuery ( "<div></div>" ) . append ( "1" , "" , 3 ) . text ( ) , "13" , "If median is false-like value, subsequent arguments should not be ignored" ) ;
2009-12-06 01:06:00 +00:00
2009-03-18 21:15:38 +00:00
// using contents will get comments regular, text, and comment nodes
2015-08-16 06:59:58 +00:00
j = jQuery ( "#nonnodes" ) . contents ( ) ;
2020-03-16 20:49:29 +00:00
d = jQuery ( "<div></div>" ) . appendTo ( "#nonnodes" ) . append ( j ) ;
2012-12-04 18:21:47 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#nonnodes" ) . length , 1 , "Check node,textnode,comment append moved leaving just the div" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( d . contents ( ) . length , 3 , "Check node,textnode,comment append works" ) ;
2015-08-16 06:59:58 +00:00
d . contents ( ) . appendTo ( "#nonnodes" ) ;
2009-03-18 21:15:38 +00:00
d . remove ( ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#nonnodes" ) . contents ( ) . length , 3 , "Check node,textnode,comment append cleanup worked" ) ;
2011-04-22 01:51:23 +00:00
2015-08-16 06:59:58 +00:00
$input = jQuery ( "<input type='checkbox'/>" ) . prop ( "checked" , true ) . appendTo ( "#testForm" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( $input [ 0 ] . checked , true , "A checked checkbox that is appended stays checked" ) ;
2011-04-22 01:51:23 +00:00
2015-08-16 06:59:58 +00:00
$radioChecked = jQuery ( "input[type='radio'][name='R1']" ) . eq ( 1 ) ;
2012-12-04 18:21:47 +00:00
$radioParent = $radioChecked . parent ( ) ;
2015-08-16 06:59:58 +00:00
$radioUnchecked = jQuery ( "<input type='radio' name='R1' checked='checked'/>" ) . appendTo ( $radioParent ) ;
$radioChecked . trigger ( "click" ) ;
2012-12-04 18:21:47 +00:00
$radioUnchecked [ 0 ] . checked = false ;
2013-04-05 21:30:48 +00:00
2020-03-16 20:49:29 +00:00
jQuery ( "<div></div>" ) . insertBefore ( $radioParent ) . append ( $radioParent ) ;
2013-04-05 21:30:48 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( $radioChecked [ 0 ] . checked , true , "Reappending radios uphold which radio is checked" ) ;
assert . equal ( $radioUnchecked [ 0 ] . checked , false , "Reappending radios uphold not being checked" ) ;
2012-11-28 02:32:59 +00:00
2020-03-16 20:49:29 +00:00
assert . equal ( jQuery ( "<div></div>" ) . append ( valueObj ( "option<area></area>" ) ) [ 0 ] . childNodes . length , 2 , "HTML-string with leading text should be processed correctly" ) ;
2013-04-09 15:45:09 +00:00
}
2009-07-12 20:19:43 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append(String|Element|Array<Element>|jQuery)" , function ( assert ) {
testAppend ( manipulationBareObj , assert ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append(Function)" , function ( assert ) {
testAppend ( manipulationFunctionReturningObj , assert ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2010-01-07 18:34:16 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append(param) to object, see #11280" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 5 ) ;
2012-10-16 18:59:36 +00:00
2015-08-16 06:59:58 +00:00
var object = jQuery ( document . createElement ( "object" ) ) . appendTo ( document . body ) ;
2012-10-16 18:59:36 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( object . children ( ) . length , 0 , "object does not start with children" ) ;
2012-10-16 18:59:36 +00:00
2015-08-16 06:59:58 +00:00
object . append ( jQuery ( "<param type='wmode' name='foo'>" ) ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( object . children ( ) . length , 1 , "appended param" ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( object . children ( ) . eq ( 0 ) . attr ( "name" ) , "foo" , "param has name=foo" ) ;
2012-10-16 18:59:36 +00:00
2015-08-16 06:59:58 +00:00
object = jQuery ( "<object><param type='baz' name='bar'></object>" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( object . children ( ) . length , 1 , "object created with child param" ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( object . children ( ) . eq ( 0 ) . attr ( "name" ) , "bar" , "param has name=bar" ) ;
} ) ;
2012-10-16 18:59:36 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append(Function) returns String" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 4 ) ;
2012-12-04 18:21:47 +00:00
2013-12-11 16:34:05 +00:00
var defaultText , result , select , old ;
2010-12-07 01:37:16 +00:00
2012-12-04 18:21:47 +00:00
defaultText = "Try them out:" ;
2015-08-16 06:59:58 +00:00
old = jQuery ( "#first" ) . html ( ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
result = jQuery ( "#first" ) . append ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2011-04-12 08:47:46 +00:00
return "<b>buga</b>" ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( result . text ( ) , defaultText + "buga" , "Check if text appending works" ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
select = jQuery ( "#select3" ) ;
2010-01-07 18:34:16 +00:00
old = select . html ( ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( select . append ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2011-04-12 08:47:46 +00:00
return "<option value='appendTest'>Append Test</option>" ;
2015-08-16 06:59:58 +00:00
} ) . find ( "option:last-child" ) . attr ( "value" ) , "appendTest" , "Appending html options to select element" ) ;
} ) ;
2010-01-07 18:34:16 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append(Function) returns Element" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 2 ) ;
2013-12-11 16:34:05 +00:00
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:" ,
2015-11-10 18:26:15 +00:00
old = jQuery ( "#sap" ) . html ( ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . append ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2015-08-16 06:59:58 +00:00
return document . getElementById ( "first" ) ;
} ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for appending of element" ) ;
} ) ;
2010-01-07 18:34:16 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append(Function) returns Array<Element>" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2013-12-11 16:34:05 +00:00
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo" ,
2015-11-10 18:26:15 +00:00
old = jQuery ( "#sap" ) . html ( ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . append ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2015-08-16 06:59:58 +00:00
return [ document . getElementById ( "first" ) , document . getElementById ( "yahoo" ) ] ;
} ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for appending of array of elements" ) ;
} ) ;
2010-01-07 18:34:16 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append(Function) returns jQuery" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2013-12-11 16:34:05 +00:00
var expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:" ,
2015-11-10 18:26:15 +00:00
old = jQuery ( "#sap" ) . html ( ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . append ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2015-08-16 06:59:58 +00:00
return jQuery ( "#yahoo, #first" ) ;
} ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for appending of jQuery object" ) ;
} ) ;
2010-01-07 18:34:16 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append(Function) returns Number" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2015-08-16 06:59:58 +00:00
var old = jQuery ( "#sap" ) . html ( ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . append ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2010-01-07 18:34:16 +00:00
return 5 ;
2015-08-16 06:59:58 +00:00
} ) ;
assert . ok ( jQuery ( "#sap" ) [ 0 ] . innerHTML . match ( /5$/ ) , "Check for appending a number" ) ;
} ) ;
2009-07-12 20:19:43 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "XML DOM manipulation (#9960)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 5 ) ;
2012-09-07 18:12:24 +00:00
2016-02-25 00:18:55 +00:00
var xmlDoc1 = jQuery . parseXML ( "<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state x='100' y='100' initial='actions' id='provisioning'></state><state x='100' y='100' id='error'></state><state x='100' y='100' id='finished' final='true'></state></scxml>" ) ,
2015-08-16 06:59:58 +00:00
xmlDoc2 = jQuery . parseXML ( "<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning3'></state></scxml>" ) ,
2012-09-07 18:12:24 +00:00
xml1 = jQuery ( xmlDoc1 ) ,
xml2 = jQuery ( xmlDoc2 ) ,
2013-02-19 04:52:29 +00:00
scxml1 = jQuery ( "scxml" , xml1 ) ,
2013-04-03 17:17:02 +00:00
scxml2 = jQuery ( "scxml" , xml2 ) ,
2015-08-16 06:59:58 +00:00
state = scxml2 . find ( "state" ) ;
2012-11-28 02:32:59 +00:00
2013-04-03 17:17:02 +00:00
scxml1 . append ( state ) ;
2015-08-16 06:59:58 +00:00
assert . strictEqual ( scxml1 [ 0 ] . lastChild , state [ 0 ] , "append" ) ;
2012-11-28 02:32:59 +00:00
2013-04-03 17:17:02 +00:00
scxml1 . prepend ( state ) ;
2015-08-16 06:59:58 +00:00
assert . strictEqual ( scxml1 [ 0 ] . firstChild , state [ 0 ] , "prepend" ) ;
2012-11-28 02:32:59 +00:00
2015-08-16 06:59:58 +00:00
scxml1 . find ( "#finished" ) . after ( state ) ;
assert . strictEqual ( scxml1 [ 0 ] . lastChild , state [ 0 ] , "after" ) ;
2012-09-07 18:12:24 +00:00
2015-08-16 06:59:58 +00:00
scxml1 . find ( "#provisioning" ) . before ( state ) ;
assert . strictEqual ( scxml1 [ 0 ] . firstChild , state [ 0 ] , "before" ) ;
2013-04-03 17:17:02 +00:00
2016-02-25 00:18:55 +00:00
scxml2 . replaceWith ( scxml1 ) ;
2015-08-16 06:59:58 +00:00
assert . deepEqual ( jQuery ( "state" , xml2 ) . get ( ) , scxml1 . find ( "state" ) . get ( ) , "replaceWith" ) ;
} ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append HTML5 sectioning elements (Bug #6485)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2012-12-04 18:21:47 +00:00
var article , aside ;
2011-09-19 20:42:36 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture" ) . append ( "<article style='font-size:10px'><section><aside>HTML5 elements</aside></section></article>" ) ;
2011-09-19 20:42:36 +00:00
2015-08-16 06:59:58 +00:00
article = jQuery ( "article" ) ;
aside = jQuery ( "aside" ) ;
2011-09-19 20:42:36 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( article . get ( 0 ) . style . fontSize , "10px" , "HTML5 elements are styleable" ) ;
assert . equal ( aside . length , 1 , "HTML5 elements do not collapse their children" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2011-10-23 20:07:07 +00:00
2019-05-13 19:39:56 +00:00
QUnit [ jQuery . fn . css ? "test" : "skip" ] ( "HTML5 Elements inherit styles from style rules (Bug #10501)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2019-05-13 19:39:56 +00:00
assert . expect ( 1 ) ;
2011-10-23 20:07:07 +00:00
2019-05-13 19:39:56 +00:00
jQuery ( "#qunit-fixture" ) . append ( "<article id='article'></article>" ) ;
jQuery ( "#article" ) . append ( "<section>This section should have a pink background.</section>" ) ;
2011-10-23 20:07:07 +00:00
2019-05-13 19:39:56 +00:00
// In IE, the missing background color will claim its value is "transparent"
assert . notEqual ( jQuery ( "section" ) . css ( "background-color" ) , "transparent" , "HTML5 elements inherit styles" ) ;
} ) ;
2011-09-19 20:42:36 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "html(String) with HTML5 (Bug #6485)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2011-09-19 20:42:36 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture" ) . html ( "<article><section><aside>HTML5 elements</aside></section></article>" ) ;
assert . equal ( jQuery ( "#qunit-fixture" ) . children ( ) . children ( ) . length , 1 , "Make sure HTML5 article elements can hold children. innerHTML shortcut path" ) ;
assert . equal ( jQuery ( "#qunit-fixture" ) . children ( ) . children ( ) . children ( ) . length , 1 , "Make sure nested HTML5 elements can hold children." ) ;
} ) ;
2011-09-19 20:42:36 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "html(String) tag-hyphenated elements (Bug #1987)" , function ( assert ) {
2015-01-05 00:02:39 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 27 ) ;
2015-01-05 00:02:39 +00:00
2015-08-16 06:59:58 +00:00
jQuery . each ( "thead tbody tfoot colgroup caption tr th td" . split ( " " ) , function ( i , name ) {
var j = jQuery ( "<" + name + "-d></" + name + "-d><" + name + "-d></" + name + "-d>" ) ;
assert . ok ( j [ 0 ] , "Create a tag-hyphenated element" ) ;
2017-01-17 16:52:50 +00:00
assert . ok ( j [ 0 ] . nodeName === name . toUpperCase ( ) + "-D" , "Hyphenated node name" ) ;
assert . ok ( j [ 1 ] . nodeName === name . toUpperCase ( ) + "-D" , "Hyphenated node name" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-01-05 00:02:39 +00:00
2015-08-16 06:59:58 +00:00
var j = jQuery ( "<tr-multiple-hyphens><td-with-hyphen>text</td-with-hyphen></tr-multiple-hyphens>" ) ;
2017-01-17 16:52:50 +00:00
assert . ok ( j [ 0 ] . nodeName === "TR-MULTIPLE-HYPHENS" , "Tags with multiple hyphens" ) ;
assert . ok ( j . children ( ) [ 0 ] . nodeName === "TD-WITH-HYPHEN" , "Tags with multiple hyphens" ) ;
2015-12-04 06:49:23 +00:00
assert . equal ( j . children ( ) . text ( ) , "text" , "Tags with multiple hyphens behave normally" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-01-05 00:02:39 +00:00
2015-10-07 04:51:23 +00:00
QUnit . test ( "Tag name processing respects the HTML Standard (gh-2005)" , function ( assert ) {
assert . expect ( 240 ) ;
var wrapper = jQuery ( "<div></div>" ) ,
nameTerminatingChars = "\x20\t\r\n\f" . split ( "" ) ,
specialChars = "[ ] { } _ - = + \\ ( ) * & ^ % $ # @ ! ~ ` ' ; ? ¥ « µ λ ⊕ ≈ ξ ℜ ♣ €"
. split ( " " ) ;
specialChars . push ( specialChars . join ( "" ) ) ;
jQuery . each ( specialChars , function ( i , characters ) {
assertSpecialCharsSupport ( "html" , characters ) ;
assertSpecialCharsSupport ( "append" , characters ) ;
} ) ;
jQuery . each ( nameTerminatingChars , function ( i , character ) {
assertNameTerminatingCharsHandling ( "html" , character ) ;
assertNameTerminatingCharsHandling ( "append" , character ) ;
} ) ;
function buildChild ( method , html ) {
wrapper [ method ] ( html ) ;
return wrapper . children ( ) [ 0 ] ;
}
function assertSpecialCharsSupport ( method , characters ) {
var child ,
codepoint = characters . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( ) ,
description = characters . length === 1 ?
"U+" + ( "000" + codepoint ) . slice ( - 4 ) + " " + characters :
"all special characters" ,
nodeName = "valid" + characters + "tagname" ;
child = buildChild ( method , "<" + nodeName + "></" + nodeName + ">" ) ;
assert . equal ( child . nodeName . toUpperCase ( ) , nodeName . toUpperCase ( ) ,
method + "(): Paired tag name includes " + description ) ;
child = buildChild ( method , "<" + nodeName + ">" ) ;
assert . equal ( child . nodeName . toUpperCase ( ) , nodeName . toUpperCase ( ) ,
method + "(): Unpaired tag name includes " + description ) ;
child = buildChild ( method , "<" + nodeName + "/>" ) ;
assert . equal ( child . nodeName . toUpperCase ( ) , nodeName . toUpperCase ( ) ,
method + "(): Self-closing tag name includes " + description ) ;
}
function assertNameTerminatingCharsHandling ( method , character ) {
var child ,
codepoint = character . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( ) ,
description = "U+" + ( "000" + codepoint ) . slice ( - 4 ) + " " + character ,
nodeName = "div" + character + "this-will-be-discarded" ;
child = buildChild ( method , "<" + nodeName + "></" + nodeName + ">" ) ;
assert . equal ( child . nodeName . toUpperCase ( ) , "DIV" ,
method + "(): Paired tag name terminated by " + description ) ;
child = buildChild ( method , "<" + nodeName + ">" ) ;
assert . equal ( child . nodeName . toUpperCase ( ) , "DIV" ,
method + "(): Unpaired open tag name terminated by " + description ) ;
child = buildChild ( method , "<" + nodeName + "/>" ) ;
assert . equal ( child . nodeName . toUpperCase ( ) , "DIV" ,
method + "(): Self-closing tag name terminated by " + description ) ;
}
} ) ;
2015-08-16 03:45:28 +00:00
QUnit . test ( "IE8 serialization bug" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2015-08-16 06:59:58 +00:00
var wrapper = jQuery ( "<div></div>" ) ;
2012-04-05 16:12:38 +00:00
2015-08-16 06:59:58 +00:00
wrapper . html ( "<div></div><article></article>" ) ;
assert . equal ( wrapper . children ( "article" ) . length , 1 , "HTML5 elements are insertable with .html()" ) ;
2012-04-11 16:00:42 +00:00
2015-08-16 06:59:58 +00:00
wrapper . html ( "<div></div><link></link>" ) ;
assert . equal ( wrapper . children ( "link" ) . length , 1 , "Link elements are insertable with .html()" ) ;
} ) ;
2012-04-05 16:12:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "html() object element #10324" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2012-03-23 15:31:05 +00:00
2015-08-16 06:59:58 +00:00
var object = jQuery ( "<object id='object2'><param name='object2test' value='test'></param></object>?" ) . appendTo ( "#qunit-fixture" ) ,
2012-12-04 18:21:47 +00:00
clone = object . clone ( ) ;
2012-03-23 15:31:05 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( clone . html ( ) , object . html ( ) , "html() returns correct innerhtml of cloned object elements" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-03-23 15:31:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append(xml)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2011-05-26 00:48:59 +00:00
2012-12-04 18:21:47 +00:00
var xmlDoc , xml1 , xml2 ;
2011-05-26 00:48:59 +00:00
function createXMLDoc ( ) {
2019-04-29 20:56:09 +00:00
return document . implementation . createDocument ( "" , "" , null ) ;
2011-05-26 00:48:59 +00:00
}
2012-12-04 18:21:47 +00:00
xmlDoc = createXMLDoc ( ) ;
2015-08-16 06:59:58 +00:00
xml1 = xmlDoc . createElement ( "head" ) ;
xml2 = xmlDoc . createElement ( "test" ) ;
2011-05-26 00:48:59 +00:00
2015-08-16 06:59:58 +00:00
assert . ok ( jQuery ( xml1 ) . append ( xml2 ) , "Append an xml element to another without raising an exception." ) ;
2011-05-26 00:48:59 +00:00
2015-08-16 06:59:58 +00:00
} ) ;
2011-05-26 00:48:59 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "appendTo(String)" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 4 ) ;
2010-02-13 08:14:00 +00:00
2013-12-11 16:34:05 +00:00
var l , defaultText ;
2012-06-21 19:30:24 +00:00
2012-12-04 18:21:47 +00:00
defaultText = "Try them out:" ;
2015-08-16 06:59:58 +00:00
jQuery ( "<b>buga</b>" ) . appendTo ( "#first" ) ;
assert . equal ( jQuery ( "#first" ) . text ( ) , defaultText + "buga" , "Check if text appending works" ) ;
assert . equal ( jQuery ( "<option value='appendTest'>Append Test</option>" ) . appendTo ( "#select3" ) . parent ( ) . find ( "option:last-child" ) . attr ( "value" ) , "appendTest" , "Appending html options to select element" ) ;
l = jQuery ( "#first" ) . children ( ) . length + 2 ;
jQuery ( "<strong>test</strong>" ) ;
jQuery ( "<strong>test</strong>" ) ;
jQuery ( [ jQuery ( "<strong>test</strong>" ) [ 0 ] , jQuery ( "<strong>test</strong>" ) [ 0 ] ] )
. appendTo ( "#first" ) ;
assert . equal ( jQuery ( "#first" ) . children ( ) . length , l , "Make sure the elements were inserted." ) ;
assert . equal ( jQuery ( "#first" ) . children ( ) . last ( ) [ 0 ] . nodeName . toLowerCase ( ) , "strong" , "Verify the last element." ) ;
} ) ;
2010-03-05 05:07:57 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "appendTo(Element|Array<Element>)" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 2 ) ;
2014-02-11 18:59:14 +00:00
2013-12-11 16:34:05 +00:00
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:" ;
2015-08-16 06:59:58 +00:00
jQuery ( document . getElementById ( "first" ) ) . appendTo ( "#sap" ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for appending of element" ) ;
2009-03-18 21:15:38 +00:00
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( [ document . getElementById ( "first" ) , document . getElementById ( "yahoo" ) ] ) . appendTo ( "#sap" ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for appending of array of elements" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "appendTo(jQuery)" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 10 ) ;
2014-02-11 18:59:14 +00:00
2015-11-10 18:26:15 +00:00
var expected , num , div ;
2015-08-16 06:59:58 +00:00
assert . ok ( jQuery ( document . createElement ( "script" ) ) . appendTo ( "body" ) . length , "Make sure a disconnected script can be appended." ) ;
2009-03-18 21:15:38 +00:00
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo, #first" ) . appendTo ( "#sap" ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for appending of jQuery object" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#select1" ) . appendTo ( "#foo" ) ;
2015-09-08 00:26:29 +00:00
assert . t ( "Append select" , "#foo select" , [ "select1" ] ) ;
2009-03-18 21:15:38 +00:00
2020-03-16 20:49:29 +00:00
div = jQuery ( "<div></div>" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "Running a cloned click." ) ;
2015-08-16 06:59:58 +00:00
} ) ;
div . appendTo ( "#qunit-fixture, #moretests" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture div" ) . last ( ) . trigger ( "click" ) ;
jQuery ( "#moretests div" ) . last ( ) . trigger ( "click" ) ;
2009-03-18 21:15:38 +00:00
2020-03-16 20:49:29 +00:00
div = jQuery ( "<div></div>" ) . appendTo ( "#qunit-fixture, #moretests" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( div . length , 2 , "appendTo returns the inserted elements" ) ;
2009-07-21 09:17:33 +00:00
2015-08-16 06:59:58 +00:00
div . addClass ( "test" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
assert . ok ( jQuery ( "#qunit-fixture div" ) . last ( ) . hasClass ( "test" ) , "appendTo element was modified after the insertion" ) ;
assert . ok ( jQuery ( "#moretests div" ) . last ( ) . hasClass ( "test" ) , "appendTo element was modified after the insertion" ) ;
2010-02-13 07:49:04 +00:00
2020-03-16 20:49:29 +00:00
div = jQuery ( "<div></div>" ) ;
2015-08-16 06:59:58 +00:00
jQuery ( "<span>a</span><b>b</b>" ) . filter ( "span" ) . appendTo ( div ) ;
2010-02-13 07:49:04 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( div . children ( ) . length , 1 , "Make sure the right number of children were inserted." ) ;
2010-02-13 08:14:00 +00:00
2015-08-16 06:59:58 +00:00
div = jQuery ( "#moretests div" ) ;
2010-02-13 08:14:00 +00:00
2015-08-16 06:59:58 +00:00
num = jQuery ( "#qunit-fixture div" ) . length ;
div . remove ( ) . appendTo ( "#qunit-fixture" ) ;
2010-02-13 08:14:00 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#qunit-fixture div" ) . length , num , "Make sure all the removed divs were inserted." ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prepend(String)" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2012-12-04 18:21:47 +00:00
2013-12-11 16:34:05 +00:00
var result , expected ;
expected = "Try them out:" ;
2015-08-16 06:59:58 +00:00
result = jQuery ( "#first" ) . prepend ( "<b>buga</b>" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( result . text ( ) , "buga" + expected , "Check if text prepending works" ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#select3" ) . prepend ( "<option value='prependTest'>Prepend Test</option>" ) . find ( "option:first-child" ) . attr ( "value" ) , "prependTest" , "Prepending html options to select element" ) ;
} ) ;
2012-06-21 19:30:24 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prepend(Element)" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2009-03-18 21:15:38 +00:00
2013-12-11 16:34:05 +00:00
var expected ;
2012-12-04 18:21:47 +00:00
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . prepend ( document . getElementById ( "first" ) ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for prepending of element" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prepend(Array<Element>)" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
2009-03-18 21:15:38 +00:00
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . prepend ( [ document . getElementById ( "first" ) , document . getElementById ( "yahoo" ) ] ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for prepending of array of elements" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prepend(jQuery)" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
2009-03-18 21:15:38 +00:00
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . prepend ( jQuery ( "#yahoo, #first" ) ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for prepending of jQuery object" ) ;
} ) ;
2012-06-16 02:17:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prepend(Array<jQuery>)" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
2012-06-16 02:17:05 +00:00
expected = "Try them out:GoogleYahooThis link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . prepend ( [ jQuery ( "#first" ) , jQuery ( "#yahoo, #google" ) ] ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for prepending of array of jQuery objects" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prepend(Function) with incoming value -- String" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 4 ) ;
2012-12-04 18:21:47 +00:00
2013-12-11 16:34:05 +00:00
var defaultText , old , result ;
2010-12-07 01:37:16 +00:00
2012-12-04 18:21:47 +00:00
defaultText = "Try them out:" ;
2015-08-16 06:59:58 +00:00
old = jQuery ( "#first" ) . html ( ) ;
result = jQuery ( "#first" ) . prepend ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2011-04-12 08:47:46 +00:00
return "<b>buga</b>" ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-12-04 18:21:47 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( result . text ( ) , "buga" + defaultText , "Check if text prepending works" ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
old = jQuery ( "#select3" ) . html ( ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#select3" ) . prepend ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2011-04-12 08:47:46 +00:00
return "<option value='prependTest'>Prepend Test</option>" ;
2015-08-16 06:59:58 +00:00
} ) . find ( "option:first-child" ) . attr ( "value" ) , "prependTest" , "Prepending html options to select element" ) ;
} ) ;
2010-01-07 18:34:16 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prepend(Function) with incoming value -- Element" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 2 ) ;
2013-12-11 16:34:05 +00:00
var old , expected ;
2012-12-04 18:21:47 +00:00
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
old = jQuery ( "#sap" ) . html ( ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . prepend ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2015-08-16 06:59:58 +00:00
return document . getElementById ( "first" ) ;
} ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for prepending of element" ) ;
} ) ;
2010-01-07 18:34:16 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prepend(Function) with incoming value -- Array<Element>" , function ( assert ) {
2014-02-11 18:59:14 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 2 ) ;
2013-12-11 16:34:05 +00:00
var old , expected ;
2010-01-07 18:34:16 +00:00
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
old = jQuery ( "#sap" ) . html ( ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . prepend ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2015-08-16 06:59:58 +00:00
return [ document . getElementById ( "first" ) , document . getElementById ( "yahoo" ) ] ;
} ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for prepending of array of elements" ) ;
} ) ;
2010-01-07 18:34:16 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prepend(Function) with incoming value -- jQuery" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 2 ) ;
2013-12-11 16:34:05 +00:00
var old , expected ;
2010-01-07 18:34:16 +00:00
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
old = jQuery ( "#sap" ) . html ( ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#sap" ) . prepend ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , old , "Make sure the incoming value is correct." ) ;
2015-08-16 06:59:58 +00:00
return jQuery ( "#yahoo, #first" ) ;
} ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for prepending of jQuery object" ) ;
} ) ;
2009-07-12 20:19:43 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prependTo(String)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2012-12-05 02:50:22 +00:00
2013-12-11 16:34:05 +00:00
var defaultText ;
2012-12-04 18:21:47 +00:00
defaultText = "Try them out:" ;
2015-08-16 06:59:58 +00:00
jQuery ( "<b>buga</b>" ) . prependTo ( "#first" ) ;
assert . equal ( jQuery ( "#first" ) . text ( ) , "buga" + defaultText , "Check if text prepending works" ) ;
assert . equal ( jQuery ( "<option value='prependTest'>Prepend Test</option>" ) . prependTo ( "#select3" ) . parent ( ) . find ( "option:first-child" ) . attr ( "value" ) , "prependTest" , "Prepending html options to select element" ) ;
2014-02-11 18:59:14 +00:00
2015-08-16 06:59:58 +00:00
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prependTo(Element)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
2009-03-18 21:15:38 +00:00
2012-12-04 18:21:47 +00:00
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
jQuery ( document . getElementById ( "first" ) ) . prependTo ( "#sap" ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for prepending of element" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prependTo(Array<Element>)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
2009-03-18 21:15:38 +00:00
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
jQuery ( [ document . getElementById ( "first" ) , document . getElementById ( "yahoo" ) ] ) . prependTo ( "#sap" ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for prepending of array of elements" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prependTo(jQuery)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
2009-03-18 21:15:38 +00:00
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo, #first" ) . prependTo ( "#sap" ) ;
assert . equal ( jQuery ( "#sap" ) . text ( ) , expected , "Check for prepending of jQuery object" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "prependTo(Array<jQuery>)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "<select id='prependSelect1'></select>" ) . prependTo ( "#form" ) ;
jQuery ( "<select id='prependSelect2'><option>Test</option></select>" ) . prependTo ( "#form" ) ;
2009-03-18 21:15:38 +00:00
2015-09-08 00:26:29 +00:00
assert . t ( "Prepend Select" , "#prependSelect2, #prependSelect1" , [ "prependSelect2" , "prependSelect1" ] ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(String)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2012-12-05 02:50:22 +00:00
2013-12-11 16:34:05 +00:00
var expected ;
2012-12-04 18:21:47 +00:00
expected = "This is a normal link: bugaYahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . before ( manipulationBareObj ( "<b>buga</b>" ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert String before" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(Element)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
2009-03-18 21:15:38 +00:00
expected = "This is a normal link: Try them out:Yahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . before ( manipulationBareObj ( document . getElementById ( "first" ) ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert element before" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(Array<Element>)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2009-03-18 21:15:38 +00:00
2013-12-11 16:34:05 +00:00
var expected ;
2009-03-18 21:15:38 +00:00
expected = "This is a normal link: Try them out:diveintomarkYahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . before ( manipulationBareObj ( [ document . getElementById ( "first" ) , document . getElementById ( "mark" ) ] ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert array of elements before" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(jQuery)" , function ( assert ) {
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
2009-03-18 21:15:38 +00:00
expected = "This is a normal link: diveintomarkTry them out:Yahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . before ( manipulationBareObj ( jQuery ( "#mark, #first" ) ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert jQuery before" ) ;
} ) ;
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(Array<jQuery>)" , function ( assert ) {
2009-09-14 22:09:42 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
2012-06-16 02:17:05 +00:00
expected = "This is a normal link: Try them out:GooglediveintomarkYahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . before ( manipulationBareObj ( [ jQuery ( "#first" ) , jQuery ( "#mark, #google" ) ] ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert array of jQuery objects before" ) ;
} ) ;
2012-06-16 02:17:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(Function) -- Returns String" , function ( assert ) {
2009-07-12 20:19:43 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
expected = "This is a normal link: bugaYahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . before ( manipulationFunctionReturningObj ( "<b>buga</b>" ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert String before" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(Function) -- Returns Element" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
expected = "This is a normal link: Try them out:Yahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . before ( manipulationFunctionReturningObj ( document . getElementById ( "first" ) ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert element before" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(Function) -- Returns Array<Element>" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
expected = "This is a normal link: Try them out:diveintomarkYahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . before ( manipulationFunctionReturningObj ( [ document . getElementById ( "first" ) , document . getElementById ( "mark" ) ] ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert array of elements before" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(Function) -- Returns jQuery" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
expected = "This is a normal link: diveintomarkTry them out:Yahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . before ( manipulationFunctionReturningObj ( jQuery ( "#mark, #first" ) ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert jQuery before" ) ;
} ) ;
2014-02-11 18:59:14 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(Function) -- Returns Array<jQuery>" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
var expected ;
expected = "This is a normal link: Try them out:GooglediveintomarkYahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . before ( manipulationFunctionReturningObj ( [ jQuery ( "#first" ) , jQuery ( "#mark, #google" ) ] ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert array of jQuery objects before" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before(no-op)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2013-12-11 16:34:05 +00:00
var set ;
2020-03-16 20:49:29 +00:00
set = jQuery ( "<div></div>" ) . before ( "<span>test</span>" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( set [ 0 ] . nodeName . toLowerCase ( ) , "div" , "Insert before a disconnected node should be a no-op" ) ;
assert . equal ( set . length , 1 , "Insert the element before the disconnected node. should be a no-op" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-07-12 20:19:43 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "before and after w/ empty object (#10812)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2012-12-04 18:21:47 +00:00
var res ;
2011-11-17 16:47:56 +00:00
2012-12-04 18:21:47 +00:00
res = jQuery ( "#notInTheDocument" ) . before ( "(" ) . after ( ")" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( res . length , 0 , "didn't choke on empty object" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2011-11-17 16:47:56 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( ".before() and .after() disconnected node" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 2 ) ;
2014-02-11 18:59:14 +00:00
2020-03-16 20:49:29 +00:00
assert . equal ( jQuery ( "<input type='checkbox'/>" ) . before ( "<div></div>" ) . length , 1 , "before() on disconnected node is no-op" ) ;
assert . equal ( jQuery ( "<input type='checkbox'/>" ) . after ( "<div></div>" ) . length , 1 , "after() on disconnected node is no-op" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insert with .before() on disconnected node last" , function ( assert ) {
2012-10-16 20:50:30 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expectedBefore = "This is a normal link: bugaYahoo" ;
2012-10-16 20:50:30 +00:00
2020-03-16 20:49:29 +00:00
jQuery ( "#yahoo" ) . add ( "<span></span>" ) . before ( "<b>buga</b>" ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#en" ) . text ( ) , expectedBefore , "Insert String before with disconnected node last" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insert with .before() on disconnected node first" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expectedBefore = "This is a normal link: bugaYahoo" ;
2012-10-16 20:50:30 +00:00
2020-03-16 20:49:29 +00:00
jQuery ( "<span></span>" ) . add ( "#yahoo" ) . before ( "<b>buga</b>" ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#en" ) . text ( ) , expectedBefore , "Insert String before with disconnected node first" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insert with .before() on disconnected node last" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expectedAfter = "This is a normal link: Yahoobuga" ;
2012-10-16 20:50:30 +00:00
2020-03-16 20:49:29 +00:00
jQuery ( "#yahoo" ) . add ( "<span></span>" ) . after ( "<b>buga</b>" ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#en" ) . text ( ) , expectedAfter , "Insert String after with disconnected node last" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insert with .before() on disconnected node last" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expectedAfter = "This is a normal link: Yahoobuga" ;
2012-10-16 14:17:14 +00:00
2020-03-16 20:49:29 +00:00
jQuery ( "<span></span>" ) . add ( "#yahoo" ) . after ( "<b>buga</b>" ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#en" ) . text ( ) , expectedAfter , "Insert String after with disconnected node first" ) ;
} ) ;
2012-07-10 14:14:43 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insertBefore(String)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2012-12-05 02:50:22 +00:00
2013-12-11 16:34:05 +00:00
var expected = "This is a normal link: bugaYahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "<b>buga</b>" ) . insertBefore ( "#yahoo" ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert String before" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insertBefore(Element)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: Try them out:Yahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( document . getElementById ( "first" ) ) . insertBefore ( "#yahoo" ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert element before" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insertBefore(Array<Element>)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: Try them out:diveintomarkYahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( [ document . getElementById ( "first" ) , document . getElementById ( "mark" ) ] ) . insertBefore ( "#yahoo" ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert array of elements before" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insertBefore(jQuery)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: diveintomarkTry them out:Yahoo" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#mark, #first" ) . insertBefore ( "#yahoo" ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert jQuery before" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( ".after(String)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2014-02-11 18:59:14 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: Yahoobuga" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . after ( "<b>buga</b>" ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert String after" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( ".after(Element)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: YahooTry them out:" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . after ( document . getElementById ( "first" ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert element after" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( ".after(Array<Element>)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: YahooTry them out:diveintomark" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . after ( [ document . getElementById ( "first" ) , document . getElementById ( "mark" ) ] ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert array of elements after" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( ".after(jQuery)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: YahooTry them out:Googlediveintomark" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . after ( [ jQuery ( "#first" ) , jQuery ( "#mark, #google" ) ] ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert array of jQuery objects after" ) ;
} ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( ".after(Function) returns String" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: Yahoobuga" ,
val = manipulationFunctionReturningObj ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . after ( val ( "<b>buga</b>" ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert String after" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( ".after(Function) returns Element" , function ( assert ) {
2009-03-18 21:15:38 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: YahooTry them out:" ,
val = manipulationFunctionReturningObj ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . after ( val ( document . getElementById ( "first" ) ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert element after" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( ".after(Function) returns Array<Element>" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: YahooTry them out:diveintomark" ,
val = manipulationFunctionReturningObj ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . after ( val ( [ document . getElementById ( "first" ) , document . getElementById ( "mark" ) ] ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert array of elements after" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( ".after(Function) returns jQuery" , function ( assert ) {
2009-09-14 22:09:42 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: YahooTry them out:Googlediveintomark" ,
val = manipulationFunctionReturningObj ;
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . after ( val ( [ jQuery ( "#first" ) , jQuery ( "#mark, #google" ) ] ) ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert array of jQuery objects after" ) ;
} ) ;
2012-06-16 02:17:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( ".after(disconnected node)" , function ( assert ) {
2009-07-12 20:19:43 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 2 ) ;
2009-03-18 21:15:38 +00:00
2020-03-16 20:49:29 +00:00
var set = jQuery ( "<div></div>" ) . before ( "<span>test</span>" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( set [ 0 ] . nodeName . toLowerCase ( ) , "div" , "Insert after a disconnected node should be a no-op" ) ;
assert . equal ( set . length , 1 , "Insert the element after the disconnected node should be a no-op" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-07-12 20:19:43 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insertAfter(String)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2016-05-10 09:12:28 +00:00
assert . expect ( 1 ) ;
2012-12-04 18:21:47 +00:00
2013-12-11 16:34:05 +00:00
var expected = "This is a normal link: Yahoobuga" ;
2015-08-16 06:59:58 +00:00
jQuery ( "<b>buga</b>" ) . insertAfter ( "#yahoo" ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert String after" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insertAfter(Element)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2014-02-11 18:59:14 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: YahooTry them out:" ;
2015-08-16 06:59:58 +00:00
jQuery ( document . getElementById ( "first" ) ) . insertAfter ( "#yahoo" ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert element after" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insertAfter(Array<Element>)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2014-02-11 18:59:14 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: YahooTry them out:diveintomark" ;
2015-08-16 06:59:58 +00:00
jQuery ( [ document . getElementById ( "first" ) , document . getElementById ( "mark" ) ] ) . insertAfter ( "#yahoo" ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert array of elements after" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insertAfter(jQuery)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 1 ) ;
2014-02-11 18:59:14 +00:00
2015-11-10 18:26:15 +00:00
var expected = "This is a normal link: YahoodiveintomarkTry them out:" ;
2015-08-16 06:59:58 +00:00
jQuery ( "#mark, #first" ) . insertAfter ( "#yahoo" ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , expected , "Insert jQuery after" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
function testReplaceWith ( val , assert ) {
2012-12-05 02:50:22 +00:00
2016-05-10 09:12:28 +00:00
var tmp , y , child , child2 , set , nonExistent , $div ,
2013-04-23 01:08:18 +00:00
expected = 29 ;
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( expected ) ;
2012-12-04 18:21:47 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#yahoo" ) . replaceWith ( val ( "<b id='replace'>buga</b>" ) ) ;
assert . ok ( jQuery ( "#replace" ) [ 0 ] , "Replace element with element from string" ) ;
assert . ok ( ! jQuery ( "#yahoo" ) [ 0 ] , "Verify that original element is gone, after string" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#anchor2" ) . replaceWith ( val ( document . getElementById ( "first" ) ) ) ;
assert . ok ( jQuery ( "#first" ) [ 0 ] , "Replace element with element" ) ;
assert . ok ( ! jQuery ( "#anchor2" ) [ 0 ] , "Verify that original element is gone, after element" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture" ) . append ( "<div id='bar'><div id='baz'></div></div>" ) ;
jQuery ( "#baz" ) . replaceWith ( val ( "Baz" ) ) ;
assert . equal ( jQuery ( "#bar" ) . text ( ) , "Baz" , "Replace element with text" ) ;
assert . ok ( ! jQuery ( "#baz" ) [ 0 ] , "Verify that original element is gone, after element" ) ;
2010-02-02 02:48:05 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#bar" ) . replaceWith ( "<div id='yahoo'></div>" , "..." , "<div id='baz'></div>" ) ;
assert . deepEqual ( jQuery ( "#yahoo, #baz" ) . get ( ) , q ( "yahoo" , "baz" ) , "Replace element with multiple arguments (#13722)" ) ;
assert . strictEqual ( jQuery ( "#yahoo" ) [ 0 ] . nextSibling , jQuery ( "#baz" ) [ 0 ] . previousSibling , "Argument order preserved" ) ;
assert . deepEqual ( jQuery ( "#bar" ) . get ( ) , [ ] , "Verify that original element is gone, after multiple arguments" ) ;
2013-04-03 17:17:02 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#google" ) . replaceWith ( val ( [ document . getElementById ( "first" ) , document . getElementById ( "mark" ) ] ) ) ;
assert . deepEqual ( jQuery ( "#mark, #first" ) . get ( ) , q ( "first" , "mark" ) , "Replace element with array of elements" ) ;
assert . ok ( ! jQuery ( "#google" ) [ 0 ] , "Verify that original element is gone, after array of elements" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#groups" ) . replaceWith ( val ( jQuery ( "#mark, #first" ) ) ) ;
assert . deepEqual ( jQuery ( "#mark, #first" ) . get ( ) , q ( "first" , "mark" ) , "Replace element with jQuery collection" ) ;
assert . ok ( ! jQuery ( "#groups" ) [ 0 ] , "Verify that original element is gone, after jQuery collection" ) ;
2013-04-03 17:17:02 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#mark, #first" ) . replaceWith ( val ( "<span class='replacement'></span><span class='replacement'></span>" ) ) ;
assert . equal ( jQuery ( "#qunit-fixture .replacement" ) . length , 4 , "Replace multiple elements (#12449)" ) ;
assert . deepEqual ( jQuery ( "#mark, #first" ) . get ( ) , [ ] , "Verify that original elements are gone, after replace multiple" ) ;
2009-09-14 22:09:42 +00:00
2015-08-16 06:59:58 +00:00
tmp = jQuery ( "<b>content</b>" ) [ 0 ] ;
jQuery ( "#anchor1" ) . contents ( ) . replaceWith ( val ( tmp ) ) ;
assert . deepEqual ( jQuery ( "#anchor1" ) . contents ( ) . get ( ) , [ tmp ] , "Replace text node with element" ) ;
2013-01-16 17:55:56 +00:00
2020-03-16 20:49:29 +00:00
tmp = jQuery ( "<div></div>" ) . appendTo ( "#qunit-fixture" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "Newly bound click run." ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2020-03-16 20:49:29 +00:00
y = jQuery ( "<div></div>" ) . appendTo ( "#qunit-fixture" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( false , "Previously bound click run." ) ;
2015-08-16 06:59:58 +00:00
} ) ;
child = y . append ( "<b>test</b>" ) . find ( "b" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "Child bound click run." ) ;
2012-12-04 18:21:47 +00:00
return false ;
2015-08-16 06:59:58 +00:00
} ) ;
2010-01-11 21:08:39 +00:00
2015-08-16 06:59:58 +00:00
y . replaceWith ( val ( tmp ) ) ;
2010-01-11 21:25:01 +00:00
2015-08-16 06:59:58 +00:00
tmp . trigger ( "click" ) ;
y . trigger ( "click" ) ; // Shouldn't be run
child . trigger ( "click" ) ; // Shouldn't be run
2010-01-11 21:25:01 +00:00
2020-03-16 20:49:29 +00:00
y = jQuery ( "<div></div>" ) . appendTo ( "#qunit-fixture" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( false , "Previously bound click run." ) ;
2015-08-16 06:59:58 +00:00
} ) ;
child2 = y . append ( "<u>test</u>" ) . find ( "u" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "Child 2 bound click run." ) ;
2012-12-04 18:21:47 +00:00
return false ;
2015-08-16 06:59:58 +00:00
} ) ;
2010-01-11 21:25:01 +00:00
2015-08-16 06:59:58 +00:00
y . replaceWith ( val ( child2 ) ) ;
2010-01-11 20:57:45 +00:00
2015-08-16 06:59:58 +00:00
child2 . trigger ( "click" ) ;
2010-01-11 20:57:45 +00:00
2020-03-16 20:49:29 +00:00
set = jQuery ( "<div></div>" ) . replaceWith ( val ( "<span>test</span>" ) ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( set [ 0 ] . nodeName . toLowerCase ( ) , "div" , "No effect on a disconnected node." ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( set . length , 1 , "No effect on a disconnected node." ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( set [ 0 ] . childNodes . length , 0 , "No effect on a disconnected node." ) ;
2009-12-05 20:30:36 +00:00
2015-08-16 06:59:58 +00:00
child = jQuery ( "#qunit-fixture" ) . children ( ) . first ( ) ;
2020-03-16 20:49:29 +00:00
$div = jQuery ( "<div class='pathological'></div>" ) . insertBefore ( child ) ;
2013-04-23 01:08:18 +00:00
$div . replaceWith ( $div ) ;
2015-08-16 03:45:28 +00:00
assert . deepEqual ( jQuery ( ".pathological" , "#qunit-fixture" ) . get ( ) , $div . get ( ) ,
2013-04-23 01:08:18 +00:00
"Self-replacement" ) ;
$div . replaceWith ( child ) ;
2015-08-16 06:59:58 +00:00
assert . deepEqual ( jQuery ( "#qunit-fixture" ) . children ( ) . first ( ) . get ( ) , child . get ( ) ,
2013-04-23 01:08:18 +00:00
"Replacement with following sibling (#13810)" ) ;
2015-08-16 03:45:28 +00:00
assert . deepEqual ( jQuery ( ".pathological" , "#qunit-fixture" ) . get ( ) , [ ] ,
2013-04-23 01:08:18 +00:00
"Replacement with following sibling (context removed)" ) ;
2016-05-10 09:12:28 +00:00
nonExistent = jQuery ( "#does-not-exist" ) . replaceWith ( val ( "<b>should not throw an error</b>" ) ) ;
assert . equal ( nonExistent . length , 0 , "Length of non existent element." ) ;
2010-10-09 15:41:58 +00:00
2015-08-16 06:59:58 +00:00
$div = jQuery ( "<div class='replacewith'></div>" ) . appendTo ( "#qunit-fixture" ) ;
$div . replaceWith ( val ( "<div class='replacewith'></div><script>" +
2019-02-18 18:02:38 +00:00
"QUnit.assert.equal( jQuery('.replacewith').length, 1, 'Check number of elements in page.' );" +
2015-08-16 06:59:58 +00:00
"</script>" ) ) ;
2010-10-09 15:41:58 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture" ) . append ( "<div id='replaceWith'></div>" ) ;
assert . equal ( jQuery ( "#qunit-fixture" ) . find ( "div[id=replaceWith]" ) . length , 1 , "Make sure only one div exists." ) ;
jQuery ( "#replaceWith" ) . replaceWith ( val ( "<div id='replaceWith'></div>" ) ) ;
assert . equal ( jQuery ( "#qunit-fixture" ) . find ( "div[id=replaceWith]" ) . length , 1 , "Make sure only one div exists after replacement." ) ;
jQuery ( "#replaceWith" ) . replaceWith ( val ( "<div id='replaceWith'></div>" ) ) ;
assert . equal ( jQuery ( "#qunit-fixture" ) . find ( "div[id=replaceWith]" ) . length , 1 , "Make sure only one div exists after subsequent replacement." ) ;
2013-01-16 17:30:47 +00:00
return expected ;
2013-04-09 15:45:09 +00:00
}
2009-07-12 21:08:54 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "replaceWith(String|Element|Array<Element>|jQuery)" , function ( assert ) {
testReplaceWith ( manipulationBareObj , assert ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "replaceWith(Function)" , function ( assert ) {
2015-08-16 06:59:58 +00:00
assert . expect ( testReplaceWith ( manipulationFunctionReturningObj , assert ) + 1 ) ;
2010-01-26 00:22:28 +00:00
2015-08-16 06:59:58 +00:00
var y = jQuery ( "#foo" ) [ 0 ] ;
2010-01-26 00:22:28 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( y ) . replaceWith ( function ( ) {
2015-08-16 03:45:28 +00:00
assert . equal ( this , y , "Make sure the context is coming in correctly." ) ;
2015-08-16 06:59:58 +00:00
} ) ;
} ) ;
2010-02-02 02:53:31 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "replaceWith(string) for more than one element" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 3 ) ;
2010-02-02 02:53:31 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#foo p" ) . length , 3 , "ensuring that test data has not changed" ) ;
2010-02-02 02:53:31 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#foo p" ) . replaceWith ( "<span>bar</span>" ) ;
assert . equal ( jQuery ( "#foo span" ) . length , 3 , "verify that all the three original element have been replaced" ) ;
assert . equal ( jQuery ( "#foo p" ) . length , 0 , "verify that all the three original element have been replaced" ) ;
} ) ;
2009-07-12 21:08:54 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Empty replaceWith (trac-13401; trac-13596; gh-2204)" , function ( assert ) {
2015-04-13 20:05:48 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 25 ) ;
2015-04-13 20:05:48 +00:00
2020-03-16 20:49:29 +00:00
var $el = jQuery ( "<div></div><div></div>" ) . html ( "<p>0</p>" ) ,
2015-04-13 20:05:48 +00:00
expectedHTML = $el . html ( ) ,
2013-04-03 17:17:02 +00:00
tests = {
"empty string" : "" ,
"empty array" : [ ] ,
2015-04-13 20:05:48 +00:00
"array of empty string" : [ "" ] ,
2013-09-17 09:24:27 +00:00
"empty collection" : jQuery ( "#nonexistent" ) ,
2015-04-13 20:05:48 +00:00
// in case of jQuery(...).replaceWith();
"undefined" : undefined
2013-04-03 17:17:02 +00:00
} ;
jQuery . each ( tests , function ( label , input ) {
2020-03-16 20:49:29 +00:00
$el . html ( "<a></a>" ) . children ( ) . replaceWith ( input ) ;
2015-08-16 03:45:28 +00:00
assert . strictEqual ( $el . html ( ) , "" , "replaceWith(" + label + ")" ) ;
2020-03-16 20:49:29 +00:00
$el . html ( "<b></b>" ) . children ( ) . replaceWith ( function ( ) { return input ; } ) ;
2015-08-16 03:45:28 +00:00
assert . strictEqual ( $el . html ( ) , "" , "replaceWith(function returning " + label + ")" ) ;
2020-03-16 20:49:29 +00:00
$el . html ( "<i></i>" ) . children ( ) . replaceWith ( function ( i ) { return input ; } ) ;
2015-08-16 03:45:28 +00:00
assert . strictEqual ( $el . html ( ) , "" , "replaceWith(other function returning " + label + ")" ) ;
2020-03-16 20:49:29 +00:00
$el . html ( "<p></p>" ) . children ( ) . replaceWith ( function ( i ) {
2015-04-13 20:05:48 +00:00
return i ?
input :
jQuery ( this ) . html ( i + "" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-08-16 03:45:28 +00:00
assert . strictEqual ( $el . eq ( 0 ) . html ( ) , expectedHTML ,
2015-04-13 20:05:48 +00:00
"replaceWith(function conditionally returning context)" ) ;
2015-08-16 03:45:28 +00:00
assert . strictEqual ( $el . eq ( 1 ) . html ( ) , "" ,
2015-04-13 20:05:48 +00:00
"replaceWith(function conditionally returning " + label + ")" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
} ) ;
2013-02-07 21:43:25 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "replaceAll(String)" , function ( assert ) {
2012-12-04 18:21:47 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2012-12-04 18:21:47 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "<b id='replace'>buga</b>" ) . replaceAll ( "#yahoo" ) ;
assert . ok ( jQuery ( "#replace" ) [ 0 ] , "Replace element with string" ) ;
assert . ok ( ! jQuery ( "#yahoo" ) [ 0 ] , "Verify that original element is gone, after string" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "replaceAll(Element)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2009-07-21 09:17:33 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( document . getElementById ( "first" ) ) . replaceAll ( "#yahoo" ) ;
assert . ok ( jQuery ( "#first" ) [ 0 ] , "Replace element with element" ) ;
assert . ok ( ! jQuery ( "#yahoo" ) [ 0 ] , "Verify that original element is gone, after element" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "replaceAll(Array<Element>)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 3 ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( [ document . getElementById ( "first" ) , document . getElementById ( "mark" ) ] ) . replaceAll ( "#yahoo" ) ;
assert . ok ( jQuery ( "#first" ) [ 0 ] , "Replace element with array of elements" ) ;
assert . ok ( jQuery ( "#mark" ) [ 0 ] , "Replace element with array of elements" ) ;
assert . ok ( ! jQuery ( "#yahoo" ) [ 0 ] , "Verify that original element is gone, after array of elements" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "replaceAll(jQuery)" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 3 ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#mark, #first" ) . replaceAll ( "#yahoo" ) ;
assert . ok ( jQuery ( "#first" ) [ 0 ] , "Replace element with set of elements" ) ;
assert . ok ( jQuery ( "#mark" ) [ 0 ] , "Replace element with set of elements" ) ;
assert . ok ( ! jQuery ( "#yahoo" ) [ 0 ] , "Verify that original element is gone, after set of elements" ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "jQuery.clone() (#8017)" , function ( assert ) {
2011-01-21 16:08:15 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2011-01-21 16:08:15 +00:00
2017-12-13 06:43:30 +00:00
assert . ok ( jQuery . clone && typeof jQuery . clone === "function" , "jQuery.clone() utility exists and is a function." ) ;
2011-01-21 16:08:15 +00:00
2015-08-16 06:59:58 +00:00
var main = jQuery ( "#qunit-fixture" ) [ 0 ] ,
2012-12-04 18:21:47 +00:00
clone = jQuery . clone ( main ) ;
2011-01-21 16:08:15 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( main . childNodes . length , clone . childNodes . length , "Simple child length to ensure a large dom tree copies correctly" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2011-01-21 16:08:15 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "append to multiple elements (#8070)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2011-01-28 16:55:39 +00:00
2015-08-16 06:59:58 +00:00
var selects = jQuery ( "<select class='test8070'></select><select class='test8070'></select>" ) . appendTo ( "#qunit-fixture" ) ;
selects . append ( "<OPTION>1</OPTION><OPTION>2</OPTION>" ) ;
2011-01-28 16:55:39 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( selects [ 0 ] . childNodes . length , 2 , "First select got two nodes" ) ;
assert . equal ( selects [ 1 ] . childNodes . length , 2 , "Second select got two nodes" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2011-01-28 16:55:39 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "table manipulation" , function ( assert ) {
assert . expect ( 2 ) ;
2013-04-03 17:17:02 +00:00
2015-08-16 06:59:58 +00:00
var table = jQuery ( "<table style='font-size:16px'></table>" ) . appendTo ( "#qunit-fixture" ) . empty ( ) ,
height = table [ 0 ] . offsetHeight ;
2013-04-03 17:17:02 +00:00
2015-08-16 06:59:58 +00:00
table . append ( "<tr><td>DATA</td></tr>" ) ;
assert . ok ( table [ 0 ] . offsetHeight - height >= 15 , "appended rows are visible" ) ;
2013-04-03 17:17:02 +00:00
table . empty ( ) ;
2015-08-16 06:59:58 +00:00
height = table [ 0 ] . offsetHeight ;
table . prepend ( "<tr><td>DATA</td></tr>" ) ;
assert . ok ( table [ 0 ] . offsetHeight - height >= 15 , "prepended rows are visible" ) ;
} ) ;
2013-04-03 17:17:02 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "clone()" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 45 ) ;
2012-12-05 02:50:22 +00:00
2012-12-04 18:21:47 +00:00
var div , clone , form , body ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#en" ) . text ( ) , "This is a normal link: Yahoo" , "Assert text for #en" ) ;
assert . equal ( jQuery ( "#first" ) . append ( jQuery ( "#yahoo" ) . clone ( ) ) . text ( ) , "Try them out:Yahoo" , "Check for clone" ) ;
assert . equal ( jQuery ( "#en" ) . text ( ) , "This is a normal link: Yahoo" , "Reassert text for #en" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery . each ( "table thead tbody tfoot tr td div button ul ol li select option textarea iframe" . split ( " " ) , function ( i , nodeName ) {
2015-08-16 03:45:28 +00:00
assert . equal ( jQuery ( "<" + nodeName + "/>" ) . clone ( ) [ 0 ] . nodeName . toLowerCase ( ) , nodeName , "Clone a " + nodeName ) ;
2015-08-16 06:59:58 +00:00
} ) ;
assert . equal ( jQuery ( "<input type='checkbox' />" ) . clone ( ) [ 0 ] . nodeName . toLowerCase ( ) , "input" , "Clone a <input type='checkbox' />" ) ;
2009-03-18 21:15:38 +00:00
2012-11-08 15:05:10 +00:00
// Check cloning non-elements
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#nonnodes" ) . contents ( ) . clone ( ) . length , 3 , "Check node,textnode,comment clone works (some browsers delete comments on clone)" ) ;
2011-01-09 21:58:47 +00:00
2012-11-08 15:05:10 +00:00
// Verify that clones of clones can keep event listeners
2015-08-16 06:59:58 +00:00
div = jQuery ( "<div><ul><li>test</li></ul></div>" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "Bound event still exists." ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-12-04 18:21:47 +00:00
clone = div . clone ( true ) ; div . remove ( ) ;
div = clone . clone ( true ) ; clone . remove ( ) ;
2011-01-09 21:58:47 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( div . length , 1 , "One element cloned" ) ;
assert . equal ( div [ 0 ] . nodeName . toUpperCase ( ) , "DIV" , "DIV element cloned" ) ;
2015-08-16 06:59:58 +00:00
div . trigger ( "click" ) ;
2009-03-18 21:15:38 +00:00
2012-11-08 15:05:10 +00:00
// Manually clean up detached elements
2011-01-09 21:58:47 +00:00
div . remove ( ) ;
2012-11-08 15:05:10 +00:00
// Verify that cloned children can keep event listeners
2020-03-16 20:49:29 +00:00
div = jQuery ( "<div></div>" ) . append ( [ document . createElement ( "table" ) , document . createElement ( "table" ) ] ) ;
2015-08-16 06:59:58 +00:00
div . find ( "table" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "Bound event still exists." ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-03-18 21:15:38 +00:00
2012-12-04 18:21:47 +00:00
clone = div . clone ( true ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( clone . length , 1 , "One element cloned" ) ;
assert . equal ( clone [ 0 ] . nodeName . toUpperCase ( ) , "DIV" , "DIV element cloned" ) ;
2015-08-16 06:59:58 +00:00
clone . find ( "table" ) . trigger ( "click" ) ;
2011-01-09 21:58:47 +00:00
2012-11-08 15:05:10 +00:00
// Manually clean up detached elements
2011-01-09 21:58:47 +00:00
div . remove ( ) ;
clone . remove ( ) ;
2009-03-18 21:15:38 +00:00
2012-11-08 15:05:10 +00:00
// Make sure that doing .clone() doesn't clone event listeners
2015-08-16 06:59:58 +00:00
div = jQuery ( "<div><ul><li>test</li></ul></div>" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( false , "Bound event still exists after .clone()." ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-11-08 15:05:10 +00:00
clone = div . clone ( ) ;
2011-02-01 13:57:18 +00:00
2015-08-16 06:59:58 +00:00
clone . trigger ( "click" ) ;
2011-02-01 13:57:18 +00:00
2012-11-08 15:05:10 +00:00
// Manually clean up detached elements
clone . remove ( ) ;
div . remove ( ) ;
2011-02-01 13:57:18 +00:00
2012-11-08 15:05:10 +00:00
// Test both html() and clone() for <embed> and <object> types
2020-03-16 20:49:29 +00:00
div = jQuery ( "<div></div>" ) . html ( "<embed height='355' width='425' src='https://www.youtube.com/v/3KANI2dpXLw&hl=en'></embed>" ) ;
2011-03-09 20:44:46 +00:00
2012-12-04 18:21:47 +00:00
clone = div . clone ( true ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( clone . length , 1 , "One element cloned" ) ;
assert . equal ( clone . html ( ) , div . html ( ) , "Element contents cloned" ) ;
assert . equal ( clone [ 0 ] . nodeName . toUpperCase ( ) , "DIV" , "DIV element cloned" ) ;
2011-03-09 20:44:46 +00:00
2010-12-12 08:20:31 +00:00
// this is technically an invalid object, but because of the special
// classid instantiation it is the only kind that IE has trouble with,
2010-12-12 19:37:00 +00:00
// so let's test with it too.
2020-03-16 20:49:29 +00:00
div = jQuery ( "<div></div>" ) . html ( "<object height='355' width='425' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'> <param name='movie' value='https://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='wmode' value='transparent'> </object>" ) ;
2009-03-18 21:15:38 +00:00
2012-12-04 18:21:47 +00:00
clone = div . clone ( true ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( clone . length , 1 , "One element cloned" ) ;
assert . equal ( clone [ 0 ] . nodeName . toUpperCase ( ) , "DIV" , "DIV element cloned" ) ;
2015-08-16 06:59:58 +00:00
div = div . find ( "object" ) ;
clone = clone . find ( "object" ) ;
2012-11-08 15:05:10 +00:00
// oldIE adds extra attributes and <param> elements, so just test for existence of the defined set
2012-12-04 18:21:47 +00:00
jQuery . each ( [ "height" , "width" , "classid" ] , function ( i , attr ) {
2015-08-16 03:45:28 +00:00
assert . equal ( clone . attr ( attr ) , div . attr ( attr ) , "<object> attribute cloned: " + attr ) ;
2012-12-04 18:21:47 +00:00
} ) ;
2015-08-16 06:59:58 +00:00
( function ( ) {
2012-07-30 18:10:18 +00:00
var params = { } ;
2015-08-16 06:59:58 +00:00
clone . find ( "param" ) . each ( function ( index , param ) {
2012-11-08 15:05:10 +00:00
params [ param . attributes . name . nodeValue . toLowerCase ( ) ] =
2012-07-30 18:10:18 +00:00
param . attributes . value . nodeValue . toLowerCase ( ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-07-30 18:10:18 +00:00
2015-08-16 06:59:58 +00:00
div . find ( "param" ) . each ( function ( index , param ) {
2012-11-08 15:05:10 +00:00
var key = param . attributes . name . nodeValue . toLowerCase ( ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( params [ key ] , param . attributes . value . nodeValue . toLowerCase ( ) , "<param> cloned: " + key ) ;
2015-08-16 06:59:58 +00:00
} ) ;
} ) ( ) ;
2010-12-12 08:20:31 +00:00
// and here's a valid one.
2020-03-16 20:49:29 +00:00
div = jQuery ( "<div></div>" ) . html ( "<object height='355' width='425' type='application/x-shockwave-flash' data='https://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='movie' value='https://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='wmode' value='transparent'> </object>" ) ;
2010-12-12 08:20:31 +00:00
2015-08-16 06:59:58 +00:00
clone = div . clone ( true ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( clone . length , 1 , "One element cloned" ) ;
assert . equal ( clone . html ( ) , div . html ( ) , "Element contents cloned" ) ;
assert . equal ( clone [ 0 ] . nodeName . toUpperCase ( ) , "DIV" , "DIV element cloned" ) ;
2009-12-09 21:28:58 +00:00
2020-03-16 20:49:29 +00:00
div = jQuery ( "<div></div>" ) . data ( { "a" : true } ) ;
2012-12-04 18:21:47 +00:00
clone = div . clone ( true ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( clone . data ( "a" ) , true , "Data cloned." ) ;
2012-12-04 18:21:47 +00:00
clone . data ( "a" , false ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( clone . data ( "a" ) , false , "Ensure cloned element data object was correctly modified" ) ;
assert . equal ( div . data ( "a" ) , true , "Ensure cloned element data object is copied, not referenced" ) ;
2010-02-02 02:26:47 +00:00
2011-01-09 21:58:47 +00:00
// manually clean up detached elements
div . remove ( ) ;
clone . remove ( ) ;
2015-08-16 06:59:58 +00:00
form = document . createElement ( "form" ) ;
2010-02-02 02:26:47 +00:00
form . action = "/test/" ;
2012-06-21 19:30:24 +00:00
2015-08-16 06:59:58 +00:00
div = document . createElement ( "div" ) ;
div . appendChild ( document . createTextNode ( "test" ) ) ;
2010-02-02 02:26:47 +00:00
form . appendChild ( div ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( form ) . clone ( ) . children ( ) . length , 1 , "Make sure we just get the form back." ) ;
2010-11-21 00:58:46 +00:00
2015-08-16 06:59:58 +00:00
body = jQuery ( "body" ) . clone ( ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( body . children ( ) [ 0 ] . id , "qunit" , "Make sure cloning body works" ) ;
2012-11-19 14:50:19 +00:00
body . remove ( ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2011-01-10 00:38:44 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "clone(script type=non-javascript) (#11359)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 3 ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 06:59:58 +00:00
var src = jQuery ( "<script type='text/filler'>Lorem ipsum dolor sit amet</script><q><script type='text/filler'>consectetur adipiscing elit</script></q>" ) ,
2012-12-04 18:21:47 +00:00
dest = src . clone ( ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( dest [ 0 ] . text , "Lorem ipsum dolor sit amet" , "Cloning preserves script text" ) ;
assert . equal ( dest . last ( ) . html ( ) , src . last ( ) . html ( ) , "Cloning preserves nested script text" ) ;
assert . ok ( /^\s*<scr.pt\s+type=['"]?text\/filler['"]?\s*>consectetur adipiscing elit<\/scr.pt>\s*$/i . test ( dest . last ( ) . html ( ) ) , "Cloning preserves nested script text" ) ;
2012-11-19 14:50:19 +00:00
dest . remove ( ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-02-17 19:17:20 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "clone(form element) (Bug #3879, #6655)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 5 ) ;
2012-12-05 02:50:22 +00:00
2013-02-19 04:52:29 +00:00
var clone , element ;
2015-08-16 06:59:58 +00:00
element = jQuery ( "<select><option>Foo</option><option value='selected' selected>Bar</option></select>" ) ;
2011-01-10 00:38:44 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( element . clone ( ) . find ( "option" ) . filter ( function ( ) { return this . selected ; } ) . val ( ) , "selected" , "Selected option cloned correctly" ) ;
2011-01-10 00:38:44 +00:00
2015-08-16 06:59:58 +00:00
element = jQuery ( "<input type='checkbox' value='foo'>" ) . attr ( "checked" , "checked" ) ;
2011-01-10 00:38:44 +00:00
clone = element . clone ( ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( clone . is ( ":checked" ) , element . is ( ":checked" ) , "Checked input cloned correctly" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( clone [ 0 ] . defaultValue , "foo" , "Checked input defaultValue cloned correctly" ) ;
2011-05-11 12:12:19 +00:00
2015-08-16 06:59:58 +00:00
element = jQuery ( "<input type='text' value='foo'>" ) ;
2011-01-10 00:38:44 +00:00
clone = element . clone ( ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( clone [ 0 ] . defaultValue , "foo" , "Text input defaultValue cloned correctly" ) ;
2011-01-10 00:38:44 +00:00
2015-08-16 06:59:58 +00:00
element = jQuery ( "<textarea>foo</textarea>" ) ;
2011-01-10 00:38:44 +00:00
clone = element . clone ( ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( clone [ 0 ] . defaultValue , "foo" , "Textarea defaultValue cloned correctly" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "clone(multiple selected options) (Bug #8129)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 06:59:58 +00:00
var element = jQuery ( "<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>" ) ;
2011-02-01 22:54:02 +00:00
2015-11-10 18:26:15 +00:00
function getSelectedOptions ( collection ) {
2016-05-10 09:12:28 +00:00
return collection . find ( "option" ) . filter ( function ( option ) {
2015-11-10 18:26:15 +00:00
return option . selected ;
} ) ;
}
2011-02-01 22:54:02 +00:00
2015-11-10 18:26:15 +00:00
assert . equal (
getSelectedOptions ( element . clone ( ) ) . length ,
getSelectedOptions ( element ) . length ,
"Multiple selected options cloned correctly"
) ;
2015-08-16 06:59:58 +00:00
} ) ;
2011-02-01 22:54:02 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "clone() on XML nodes" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2012-12-05 02:50:22 +00:00
2012-12-04 18:21:47 +00:00
var xml = createDashboardXML ( ) ,
2015-08-16 06:59:58 +00:00
root = jQuery ( xml . documentElement ) . clone ( ) ,
origTab = jQuery ( "tab" , xml ) . eq ( 0 ) ,
cloneTab = jQuery ( "tab" , root ) . eq ( 0 ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 06:59:58 +00:00
origTab . text ( "origval" ) ;
cloneTab . text ( "cloneval" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( origTab . text ( ) , "origval" , "Check original XML node was correctly set" ) ;
assert . equal ( cloneTab . text ( ) , "cloneval" , "Check cloned XML node was correctly set" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "clone() on local XML nodes with html5 nodename" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2012-02-10 01:48:21 +00:00
2012-02-10 21:17:12 +00:00
var $xmlDoc = jQuery ( jQuery . parseXML ( "<root><meter /></root>" ) ) ,
2012-02-10 01:48:21 +00:00
$meter = $xmlDoc . find ( "meter" ) . clone ( ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( $meter [ 0 ] . nodeName , "meter" , "Check if nodeName was not changed due to cloning" ) ;
assert . equal ( $meter [ 0 ] . nodeType , 1 , "Check if nodeType is not changed due to cloning" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-02-10 01:48:21 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "html(undefined)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#foo" ) . html ( "<i>test</i>" ) . html ( undefined ) . html ( ) . toLowerCase ( ) , "<i>test</i>" , ".html(undefined) is chainable (#5571)" ) ;
} ) ;
2011-12-06 20:25:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "html() on empty set" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . strictEqual ( jQuery ( ) . html ( ) , undefined , ".html() returns undefined for empty sets (#11962)" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-07-10 03:06:51 +00:00
2013-04-09 15:45:09 +00:00
function childNodeNames ( node ) {
2012-11-19 14:50:19 +00:00
return jQuery . map ( node . childNodes , function ( child ) {
return child . nodeName . toUpperCase ( ) ;
2015-08-16 06:59:58 +00:00
} ) . join ( " " ) ;
2013-04-09 15:45:09 +00:00
}
2009-07-21 09:17:33 +00:00
2015-08-16 03:45:28 +00:00
function testHtml ( valueObj , assert ) {
assert . expect ( 40 ) ;
2009-07-21 09:17:33 +00:00
2012-11-19 14:50:19 +00:00
var actual , expected , tmp ,
2015-08-16 06:59:58 +00:00
div = jQuery ( "<div></div>" ) ,
fixture = jQuery ( "#qunit-fixture" ) ;
2010-01-25 02:37:05 +00:00
2020-03-16 20:49:29 +00:00
div . html ( valueObj ( "<div id='parent_1'><div id='child_1'></div></div><div id='parent_2'></div>" ) ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( div . children ( ) . length , 2 , "Found children" ) ;
assert . equal ( div . children ( ) . children ( ) . length , 1 , "Found grandchild" ) ;
2010-01-25 02:37:05 +00:00
2012-11-19 14:50:19 +00:00
actual = [ ] ; expected = [ ] ;
2020-03-16 20:49:29 +00:00
tmp = jQuery ( "<map></map>" ) . html ( valueObj ( "<area alt='area'></area>" ) ) . each ( function ( ) {
2015-08-16 06:59:58 +00:00
expected . push ( "AREA" ) ;
2012-11-19 14:50:19 +00:00
actual . push ( childNodeNames ( this ) ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( expected . length , 1 , "Expecting one parent" ) ;
assert . deepEqual ( actual , expected , "Found the inserted area element" ) ;
2010-02-06 00:58:08 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( div . html ( valueObj ( 5 ) ) . html ( ) , "5" , "Setting a number as html" ) ;
assert . equal ( div . html ( valueObj ( 0 ) ) . html ( ) , "0" , "Setting a zero as html" ) ;
assert . equal ( div . html ( valueObj ( Infinity ) ) . html ( ) , "Infinity" , "Setting Infinity as html" ) ;
assert . equal ( div . html ( valueObj ( NaN ) ) . html ( ) , "" , "Setting NaN as html" ) ;
assert . equal ( div . html ( valueObj ( 1e2 ) ) . html ( ) , "100" , "Setting exponential number notation as html" ) ;
2010-02-13 08:30:45 +00:00
2015-08-16 06:59:58 +00:00
div . html ( valueObj ( " &" ) ) ;
2015-08-16 03:45:28 +00:00
assert . equal (
2012-12-04 18:21:47 +00:00
div [ 0 ] . innerHTML . replace ( /\xA0/ , " " ) ,
2012-11-19 14:50:19 +00:00
" &" ,
"Entities are passed through correctly"
) ;
2010-02-13 08:30:45 +00:00
2012-11-19 14:50:19 +00:00
tmp = "<div>hello1</div>" ;
2015-08-16 06:59:58 +00:00
assert . equal ( div . html ( valueObj ( tmp ) ) . html ( ) . replace ( />/g , ">" ) , tmp , "Escaped html" ) ;
2012-11-19 14:50:19 +00:00
tmp = "x" + tmp ;
2015-08-16 06:59:58 +00:00
assert . equal ( div . html ( valueObj ( tmp ) ) . html ( ) . replace ( />/g , ">" ) , tmp , "Escaped html, leading x" ) ;
2012-12-04 18:21:47 +00:00
tmp = " " + tmp . slice ( 1 ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( div . html ( valueObj ( tmp ) ) . html ( ) . replace ( />/g , ">" ) , tmp , "Escaped html, leading space" ) ;
2012-11-19 14:50:19 +00:00
actual = [ ] ; expected = [ ] ; tmp = { } ;
2015-08-16 06:59:58 +00:00
jQuery ( "#nonnodes" ) . contents ( ) . html ( valueObj ( "<b>bold</b>" ) ) . each ( function ( ) {
2012-11-19 14:50:19 +00:00
var html = jQuery ( this ) . html ( ) ;
tmp [ this . nodeType ] = true ;
expected . push ( this . nodeType === 1 ? "<b>bold</b>" : undefined ) ;
actual . push ( html ? html . toLowerCase ( ) : html ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-08-16 03:45:28 +00:00
assert . deepEqual ( actual , expected , "Set containing element, text node, comment" ) ;
assert . ok ( tmp [ 1 ] , "element" ) ;
assert . ok ( tmp [ 3 ] , "text node" ) ;
assert . ok ( tmp [ 8 ] , "comment" ) ;
2012-11-19 14:50:19 +00:00
actual = [ ] ; expected = [ ] ;
2015-08-16 06:59:58 +00:00
fixture . children ( "div" ) . html ( valueObj ( "<b>test</b>" ) ) . each ( function ( ) {
expected . push ( "B" ) ;
2012-11-19 14:50:19 +00:00
actual . push ( childNodeNames ( this ) ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( expected . length , 7 , "Expecting many parents" ) ;
assert . deepEqual ( actual , expected , "Correct childNodes after setting HTML" ) ;
2009-07-21 09:17:33 +00:00
2012-11-19 14:50:19 +00:00
actual = [ ] ; expected = [ ] ;
2015-08-16 06:59:58 +00:00
fixture . html ( valueObj ( "<style>.foobar{color:green;}</style>" ) ) . each ( function ( ) {
expected . push ( "STYLE" ) ;
2012-11-19 14:50:19 +00:00
actual . push ( childNodeNames ( this ) ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( expected . length , 1 , "Expecting one parent" ) ;
assert . deepEqual ( actual , expected , "Found the inserted style element" ) ;
2009-07-21 09:17:33 +00:00
2020-03-16 20:49:29 +00:00
fixture . html ( valueObj ( "<select></select>" ) ) ;
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture select" ) . html ( valueObj ( "<option>O1</option><option selected='selected'>O2</option><option>O3</option>" ) ) ;
assert . equal ( jQuery ( "#qunit-fixture select" ) . val ( ) , "O2" , "Selected option correct" ) ;
2009-07-21 09:17:33 +00:00
2012-11-19 14:50:19 +00:00
tmp = fixture . html (
2015-08-16 06:59:58 +00:00
valueObj ( [
2019-02-18 18:02:38 +00:00
"<script type='something/else'>QUnit.assert.ok( false, 'evaluated: non-script' );</script>" ,
"<script type='text/javascript'>QUnit.assert.ok( true, 'evaluated: text/javascript' );</script>" ,
"<script type='text/ecmascript'>QUnit.assert.ok( true, 'evaluated: text/ecmascript' );</script>" ,
"<script>QUnit.assert.ok( true, 'evaluated: no type' );</script>" ,
2012-11-19 14:50:19 +00:00
"<div>" ,
2019-02-18 18:02:38 +00:00
"<script type='something/else'>QUnit.assert.ok( false, 'evaluated: inner non-script' );</script>" ,
"<script type='text/javascript'>QUnit.assert.ok( true, 'evaluated: inner text/javascript' );</script>" ,
"<script type='text/ecmascript'>QUnit.assert.ok( true, 'evaluated: inner text/ecmascript' );</script>" ,
"<script>QUnit.assert.ok( true, 'evaluated: inner no type' );</script>" ,
2012-11-19 14:50:19 +00:00
"</div>"
2015-08-16 06:59:58 +00:00
] . join ( "" ) )
) . find ( "script" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( tmp . length , 8 , "All script tags remain." ) ;
assert . equal ( tmp [ 0 ] . type , "something/else" , "Non-evaluated type." ) ;
assert . equal ( tmp [ 1 ] . type , "text/javascript" , "Evaluated type." ) ;
2012-11-19 14:50:19 +00:00
2019-02-18 18:02:38 +00:00
fixture . html ( valueObj ( "<script type='text/javascript'>QUnit.assert.ok( true, 'Injection of identical script' );</script>" ) ) ;
fixture . html ( valueObj ( "<script type='text/javascript'>QUnit.assert.ok( true, 'Injection of identical script' );</script>" ) ) ;
fixture . html ( valueObj ( "<script type='text/javascript'>QUnit.assert.ok( true, 'Injection of identical script' );</script>" ) ) ;
fixture . html ( valueObj ( "foo <form><script type='text/javascript'>QUnit.assert.ok( true, 'Injection of identical script (#975)' );</script></form>" ) ) ;
2012-11-19 14:50:19 +00:00
jQuery . scriptorder = 0 ;
2015-08-16 06:59:58 +00:00
fixture . html ( valueObj ( [
2012-11-19 14:50:19 +00:00
"<script>" ,
2019-02-18 18:02:38 +00:00
"QUnit.assert.equal( jQuery('#scriptorder').length, 1,'Execute after html' );" ,
"QUnit.assert.equal( jQuery.scriptorder++, 0, 'Script is executed in order' );" ,
2012-11-19 14:50:19 +00:00
"</script>" ,
2019-02-18 18:02:38 +00:00
"<span id='scriptorder'><script>QUnit.assert.equal( jQuery.scriptorder++, 1, 'Script (nested) is executed in order');</script></span>" ,
"<script>QUnit.assert.equal( jQuery.scriptorder++, 2, 'Script (unnested) is executed in order' );</script>"
2015-08-16 06:59:58 +00:00
] . join ( "" ) ) ) ;
2012-11-19 14:50:19 +00:00
fixture . html ( valueObj ( fixture . text ( ) ) ) ;
2015-08-16 03:45:28 +00:00
assert . ok ( /^[^<]*[^<\s][^<]*$/ . test ( fixture . html ( ) ) , "Replace html with text" ) ;
2013-04-09 15:45:09 +00:00
}
2009-07-12 20:19:43 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "html(String|Number)" , function ( assert ) {
2015-08-16 06:59:58 +00:00
testHtml ( manipulationBareObj , assert ) ;
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "html(Function)" , function ( assert ) {
2015-08-16 06:59:58 +00:00
testHtml ( manipulationFunctionReturningObj , assert ) ;
} ) ;
2009-07-12 20:19:43 +00:00
2020-09-22 15:49:28 +00:00
// Support: IE 9 - 11+
// IE doesn't support modules.
QUnit . testUnlessIE ( "html(script type module)" , function ( assert ) {
2018-01-16 20:18:32 +00:00
assert . expect ( 4 ) ;
var done = assert . async ( ) ,
$fixture = jQuery ( "#qunit-fixture" ) ;
$fixture . html (
2017-12-03 09:58:09 +00:00
[
2019-02-18 18:02:38 +00:00
"<script type='module'>QUnit.assert.ok( true, 'evaluated: module' );</script>" ,
2018-01-16 20:18:32 +00:00
"<script type='module' src='" + url ( "module.js" ) + "'></script>" ,
2017-12-03 09:58:09 +00:00
"<div>" ,
2019-02-18 18:02:38 +00:00
"<script type='module'>QUnit.assert.ok( true, 'evaluated: inner module' );</script>" ,
2018-01-16 20:18:32 +00:00
"<script type='module' src='" + url ( "inner_module.js" ) + "'></script>" ,
2017-12-03 09:58:09 +00:00
"</div>"
] . join ( "" )
2018-01-16 20:18:32 +00:00
) ;
// Allow asynchronous script execution to generate assertions
setTimeout ( function ( ) {
done ( ) ;
} , 1000 ) ;
2017-12-03 09:58:09 +00:00
} ) ;
2019-04-29 20:56:09 +00:00
QUnit . test ( "html(script nomodule)" , function ( assert ) {
2019-01-21 17:34:40 +00:00
// `nomodule` scripts should be executed by legacy browsers only.
2019-05-13 19:39:56 +00:00
assert . expect ( QUnit . isIE ? 4 : 0 ) ;
2019-01-21 17:34:40 +00:00
var done = assert . async ( ) ,
$fixture = jQuery ( "#qunit-fixture" ) ;
$fixture . html (
[
2019-05-13 19:39:56 +00:00
"<script nomodule>QUnit.assert.ok( QUnit.isIE, 'evaluated: nomodule script' );</script>" ,
2019-01-21 17:34:40 +00:00
"<script nomodule src='" + url ( "nomodule.js" ) + "'></script>" ,
"<div>" ,
2019-05-13 19:39:56 +00:00
"<script nomodule>QUnit.assert.ok( QUnit.isIE, 'evaluated: inner nomodule script' );</script>" ,
2019-01-21 17:34:40 +00:00
"<script nomodule src='" + url ( "inner_nomodule.js" ) + "'></script>" ,
"</div>"
] . join ( "" )
) ;
// Allow asynchronous script execution to generate assertions
setTimeout ( function ( ) {
done ( ) ;
} , 1000 ) ;
} ) ;
2015-08-16 03:45:28 +00:00
QUnit . test ( "html(Function) with incoming value -- direct selection" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 4 ) ;
2010-12-07 01:37:16 +00:00
2013-12-11 16:34:05 +00:00
var els , actualhtml , pass ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
els = jQuery ( "#foo > p" ) ;
actualhtml = els . map ( function ( ) {
2012-12-04 18:21:47 +00:00
return jQuery ( this ) . html ( ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-12-04 18:21:47 +00:00
2015-08-16 06:59:58 +00:00
els . html ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , actualhtml [ i ] , "Make sure the incoming value is correct." ) ;
2010-01-07 18:34:16 +00:00
return "<b>test</b>" ;
2015-08-16 06:59:58 +00:00
} ) ;
2010-12-07 01:37:16 +00:00
2012-12-04 18:21:47 +00:00
pass = true ;
2015-08-16 06:59:58 +00:00
els . each ( function ( ) {
2010-01-07 18:34:16 +00:00
if ( this . childNodes . length !== 1 ) {
pass = false ;
}
2015-08-16 06:59:58 +00:00
} ) ;
2015-08-16 03:45:28 +00:00
assert . ok ( pass , "Set HTML" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "html(Function) with incoming value -- jQuery.contents()" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 14 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var actualhtml , j , $div , $div2 , insert ;
2010-01-07 18:34:16 +00:00
2015-08-16 06:59:58 +00:00
j = jQuery ( "#nonnodes" ) . contents ( ) ;
actualhtml = j . map ( function ( ) {
2012-12-04 18:21:47 +00:00
return jQuery ( this ) . html ( ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
j . html ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , actualhtml [ i ] , "Make sure the incoming value is correct." ) ;
2010-01-07 18:34:16 +00:00
return "<b>bold</b>" ;
2015-08-16 06:59:58 +00:00
} ) ;
2010-08-27 18:16:27 +00:00
// Handle the case where no comment is in the document
if ( j . length === 2 ) {
2015-08-16 03:45:28 +00:00
assert . equal ( null , null , "Make sure the incoming value is correct." ) ;
2010-08-27 18:16:27 +00:00
}
2010-12-07 01:37:16 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( j . html ( ) . replace ( / xmlns="[^"]+"/g , "" ) . toLowerCase ( ) , "<b>bold</b>" , "Check node,textnode,comment with html()" ) ;
2010-12-07 01:37:16 +00:00
2020-03-16 20:49:29 +00:00
$div = jQuery ( "<div></div>" ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $div . html ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , "" , "Make sure the incoming value is correct." ) ;
2010-01-07 18:34:16 +00:00
return 5 ;
2015-08-16 06:59:58 +00:00
} ) . html ( ) , "5" , "Setting a number as html" ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $div . html ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , "5" , "Make sure the incoming value is correct." ) ;
2010-01-07 18:34:16 +00:00
return 0 ;
2015-08-16 06:59:58 +00:00
} ) . html ( ) , "0" , "Setting a zero as html" ) ;
2010-01-07 18:34:16 +00:00
2020-03-16 20:49:29 +00:00
$div2 = jQuery ( "<div></div>" ) ;
2012-12-04 18:21:47 +00:00
insert = "<div>hello1</div>" ;
2015-08-16 06:59:58 +00:00
assert . equal ( $div2 . html ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val , "" , "Make sure the incoming value is correct." ) ;
2010-01-07 18:34:16 +00:00
return insert ;
2015-08-16 06:59:58 +00:00
} ) . html ( ) . replace ( />/g , ">" ) , insert , "Verify escaped insertion." ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $div2 . html ( function ( i , val ) {
assert . equal ( val . replace ( />/g , ">" ) , insert , "Make sure the incoming value is correct." ) ;
2010-01-07 18:34:16 +00:00
return "x" + insert ;
2015-08-16 06:59:58 +00:00
} ) . html ( ) . replace ( />/g , ">" ) , "x" + insert , "Verify escaped insertion." ) ;
2010-12-07 01:37:16 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( $div2 . html ( function ( i , val ) {
2015-08-16 03:45:28 +00:00
assert . equal ( val . replace ( />/g , ">" ) , "x" + insert , "Make sure the incoming value is correct." ) ;
2010-01-07 18:34:16 +00:00
return " " + insert ;
2015-08-16 06:59:58 +00:00
} ) . html ( ) . replace ( />/g , ">" ) , " " + insert , "Verify escaped insertion." ) ;
} ) ;
2010-01-07 18:34:16 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 06:59:58 +00:00
var $content = jQuery ( "<div><b><i>text</i></b></div>" ) . appendTo ( "#qunit-fixture" ) ,
2012-11-10 04:43:46 +00:00
expected = /^<b><i>text<\/i><\/b>$/i ;
2013-02-19 04:52:29 +00:00
// Attach jQuery and Sizzle data (the latter with a non-qSA nth-child)
try {
2015-08-16 06:59:58 +00:00
$content . find ( ":nth-child(1):lt(4)" ) . data ( "test" , true ) ;
2013-02-19 04:52:29 +00:00
// But don't break on a non-Sizzle build
2015-08-16 06:59:58 +00:00
} catch ( e ) {
$content . find ( "*" ) . data ( "test" , true ) ;
2013-02-19 04:52:29 +00:00
}
2012-11-10 04:43:46 +00:00
2015-08-16 03:45:28 +00:00
assert . ok ( expected . test ( $content . clone ( false ) [ 0 ] . innerHTML ) , "clone()" ) ;
assert . ok ( expected . test ( $content . html ( ) ) , "html()" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-11-10 04:43:46 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "remove() no filters" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 2 ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 06:59:58 +00:00
var first = jQuery ( "#ap" ) . children ( ) . first ( ) ;
2012-06-21 19:30:24 +00:00
2015-08-16 06:59:58 +00:00
first . data ( "foo" , "bar" ) ;
2009-07-21 09:17:33 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#ap" ) . children ( ) . remove ( ) ;
assert . ok ( jQuery ( "#ap" ) . text ( ) . length > 10 , "Check text is not removed" ) ;
assert . equal ( jQuery ( "#ap" ) . children ( ) . length , 0 , "Check remove" ) ;
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "remove() with filters" , function ( assert ) {
2009-07-21 09:17:33 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 8 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var markup , div ;
2015-08-16 06:59:58 +00:00
jQuery ( "#ap" ) . children ( ) . remove ( "a" ) ;
assert . ok ( jQuery ( "#ap" ) . text ( ) . length > 10 , "Check text is not removed" ) ;
assert . equal ( jQuery ( "#ap" ) . children ( ) . length , 1 , "Check filtered remove" ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 06:59:58 +00:00
jQuery ( "#ap" ) . children ( ) . remove ( "a, code" ) ;
assert . equal ( jQuery ( "#ap" ) . children ( ) . length , 0 , "Check multi-filtered remove" ) ;
2009-03-18 21:15:38 +00:00
2013-04-05 12:57:01 +00:00
// Positional and relative selectors
markup = "<div><span>1</span><span>2</span><span>3</span><span>4</span></div>" ;
div = jQuery ( markup ) ;
2015-08-16 06:59:58 +00:00
div . children ( ) . remove ( "span:nth-child(2n)" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( div . text ( ) , "13" , "relative selector in remove" ) ;
2015-11-10 18:26:15 +00:00
2019-07-29 19:14:46 +00:00
if ( QUnit . jQuerySelectorsPos ) {
2015-11-10 18:26:15 +00:00
div = jQuery ( markup ) ;
div . children ( ) . remove ( "span:first" ) ;
assert . equal ( div . text ( ) , "234" , "positional selector in remove" ) ;
div = jQuery ( markup ) ;
div . children ( ) . remove ( "span:last" ) ;
assert . equal ( div . text ( ) , "123" , "positional selector in remove" ) ;
} else {
2019-07-29 19:14:46 +00:00
assert . ok ( "skip" , "Positional selectors are not supported" ) ;
assert . ok ( "skip" , "Positional selectors are not supported" ) ;
2015-11-10 18:26:15 +00:00
}
2013-04-05 12:57:01 +00:00
2009-03-18 21:15:38 +00:00
// using contents will get comments regular, text, and comment nodes
2010-08-27 18:16:27 +00:00
// Handle the case where no comment is in the document
2015-08-16 06:59:58 +00:00
assert . ok ( jQuery ( "#nonnodes" ) . contents ( ) . length >= 2 , "Check node,textnode,comment remove works" ) ;
jQuery ( "#nonnodes" ) . contents ( ) . remove ( ) ;
assert . equal ( jQuery ( "#nonnodes" ) . contents ( ) . length , 0 , "Check node,textnode,comment remove works" ) ;
} ) ;
2009-07-21 09:17:33 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "remove() event cleaning " , function ( assert ) {
assert . expect ( 1 ) ;
2015-07-29 15:10:04 +00:00
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
var count , first , cleanUp ;
2012-06-21 19:30:24 +00:00
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
count = 0 ;
2015-08-16 06:59:58 +00:00
first = jQuery ( "#ap" ) . children ( ) . first ( ) ;
2013-01-27 04:48:59 +00:00
cleanUp = first . on ( "click" , function ( ) {
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
count ++ ;
2015-08-16 06:59:58 +00:00
} ) . remove ( ) . appendTo ( "#qunit-fixture" ) . trigger ( "click" ) ;
2012-06-21 19:30:24 +00:00
2015-08-16 03:45:28 +00:00
assert . strictEqual ( 0 , count , "Event handler has been removed" ) ;
2010-12-07 01:37:16 +00:00
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
// Clean up detached data
2011-01-09 21:58:47 +00:00
cleanUp . remove ( ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-07-21 09:17:33 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "remove() in document order #13779" , function ( assert ) {
assert . expect ( 1 ) ;
2015-07-29 15:10:04 +00:00
2013-04-17 02:16:12 +00:00
var last ,
cleanData = jQuery . cleanData ;
jQuery . cleanData = function ( nodes ) {
2015-08-16 06:59:58 +00:00
last = jQuery . text ( nodes [ 0 ] ) ;
2013-04-17 02:16:12 +00:00
cleanData . call ( this , nodes ) ;
} ;
2015-08-16 06:59:58 +00:00
jQuery ( "#qunit-fixture" ) . append (
2013-04-17 02:16:12 +00:00
jQuery . parseHTML (
"<div class='removal-fixture'>1</div>" +
"<div class='removal-fixture'>2</div>" +
"<div class='removal-fixture'>3</div>"
)
) ;
2015-08-16 06:59:58 +00:00
jQuery ( ".removal-fixture" ) . remove ( ) ;
2013-04-17 02:16:12 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( last , 3 , "The removal fixtures were removed in document order" ) ;
2013-04-17 02:16:12 +00:00
jQuery . cleanData = cleanData ;
2015-08-16 06:59:58 +00:00
} ) ;
2013-04-17 02:16:12 +00:00
2015-08-16 06:59:58 +00:00
QUnit . test ( "detach() no filters" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 3 ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
var first = jQuery ( "#ap" ) . children ( ) . first ( ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
first . data ( "foo" , "bar" ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
jQuery ( "#ap" ) . children ( ) . detach ( ) ;
assert . ok ( jQuery ( "#ap" ) . text ( ) . length > 10 , "Check text is not removed" ) ;
assert . equal ( jQuery ( "#ap" ) . children ( ) . length , 0 , "Check remove" ) ;
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . equal ( first . data ( "foo" ) , "bar" ) ;
first . remove ( ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 06:59:58 +00:00
} ) ;
2013-12-11 16:34:05 +00:00
2015-08-16 06:59:58 +00:00
QUnit . test ( "detach() with filters" , function ( assert ) {
2013-12-11 16:34:05 +00:00
2015-11-10 18:26:15 +00:00
assert . expect ( 8 ) ;
var markup , div ;
jQuery ( "#ap" ) . children ( ) . detach ( "a" ) ;
assert . ok ( jQuery ( "#ap" ) . text ( ) . length > 10 , "Check text is not removed" ) ;
assert . equal ( jQuery ( "#ap" ) . children ( ) . length , 1 , "Check filtered remove" ) ;
jQuery ( "#ap" ) . children ( ) . detach ( "a, code" ) ;
assert . equal ( jQuery ( "#ap" ) . children ( ) . length , 0 , "Check multi-filtered remove" ) ;
// Positional and relative selectors
markup = "<div><span>1</span><span>2</span><span>3</span><span>4</span></div>" ;
div = jQuery ( markup ) ;
div . children ( ) . detach ( "span:nth-child(2n)" ) ;
assert . equal ( div . text ( ) , "13" , "relative selector in detach" ) ;
2019-07-29 19:14:46 +00:00
if ( QUnit . jQuerySelectorsPos ) {
2015-11-10 18:26:15 +00:00
div = jQuery ( markup ) ;
div . children ( ) . detach ( "span:first" ) ;
assert . equal ( div . text ( ) , "234" , "positional selector in detach" ) ;
div = jQuery ( markup ) ;
div . children ( ) . detach ( "span:last" ) ;
assert . equal ( div . text ( ) , "123" , "positional selector in detach" ) ;
} else {
2019-07-29 19:14:46 +00:00
assert . ok ( "skip" , "Positional selectors are not supported" ) ;
assert . ok ( "skip" , "Positional selectors are not supported" ) ;
2015-11-10 18:26:15 +00:00
}
// using contents will get comments regular, text, and comment nodes
// Handle the case where no comment is in the document
assert . ok ( jQuery ( "#nonnodes" ) . contents ( ) . length >= 2 , "Check node,textnode,comment remove works" ) ;
jQuery ( "#nonnodes" ) . contents ( ) . detach ( ) ;
assert . equal ( jQuery ( "#nonnodes" ) . contents ( ) . length , 0 , "Check node,textnode,comment remove works" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "detach() event cleaning " , function ( assert ) {
assert . expect ( 1 ) ;
2015-07-29 15:10:04 +00:00
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
var count , first , cleanUp ;
count = 0 ;
2015-08-16 06:59:58 +00:00
first = jQuery ( "#ap" ) . children ( ) . first ( ) ;
2013-01-27 04:48:59 +00:00
cleanUp = first . on ( "click" , function ( ) {
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
count ++ ;
2015-08-16 06:59:58 +00:00
} ) . detach ( ) . appendTo ( "#qunit-fixture" ) . trigger ( "click" ) ;
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
2015-08-16 03:45:28 +00:00
assert . strictEqual ( 1 , count , "Event handler has not been removed" ) ;
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
// Clean up detached data
cleanUp . remove ( ) ;
2015-08-16 06:59:58 +00:00
} ) ;
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
2015-08-16 06:59:58 +00:00
QUnit . test ( "empty()" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 3 ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( "#ap" ) . children ( ) . empty ( ) . text ( ) . length , 0 , "Check text is removed" ) ;
assert . equal ( jQuery ( "#ap" ) . children ( ) . length , 4 , "Check elements are not removed" ) ;
2009-03-18 21:15:38 +00:00
// using contents will get comments regular, text, and comment nodes
2015-08-16 06:59:58 +00:00
var j = jQuery ( "#nonnodes" ) . contents ( ) ;
2009-03-18 21:15:38 +00:00
j . empty ( ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( j . html ( ) , "" , "Check node,textnode,comment empty works" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2009-03-18 21:15:38 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "jQuery.cleanData" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 14 ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
var type , pos , div , child ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
type = "remove" ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
// Should trigger 4 remove event
div = getDiv ( ) . remove ( ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
// Should both do nothing
pos = "Outer" ;
2015-08-16 06:59:58 +00:00
div . trigger ( "click" ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
pos = "Inner" ;
2015-08-16 06:59:58 +00:00
div . children ( ) . trigger ( "click" ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
type = "empty" ;
div = getDiv ( ) ;
child = div . children ( ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
// Should trigger 2 remove event
div . empty ( ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
// Should trigger 1
pos = "Outer" ;
2015-08-16 06:59:58 +00:00
div . trigger ( "click" ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
// Should do nothing
pos = "Inner" ;
2015-08-16 06:59:58 +00:00
child . trigger ( "click" ) ;
2010-01-25 20:18:51 +00:00
// Should trigger 2
div . remove ( ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
type = "html" ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
div = getDiv ( ) ;
child = div . children ( ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
// Should trigger 2 remove event
2015-08-16 06:59:58 +00:00
div . html ( "<div></div>" ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
// Should trigger 1
pos = "Outer" ;
2015-08-16 06:59:58 +00:00
div . trigger ( "click" ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
// Should do nothing
pos = "Inner" ;
2015-08-16 06:59:58 +00:00
child . trigger ( "click" ) ;
2010-01-25 20:18:51 +00:00
// Should trigger 2
div . remove ( ) ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
function getDiv ( ) {
2015-08-16 06:59:58 +00:00
var div = jQuery ( "<div class='outer'><div class='inner'></div></div>" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , type + " " + pos + " Click event fired." ) ;
2015-08-16 06:59:58 +00:00
} ) . on ( "focus" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , type + " " + pos + " Focus event fired." ) ;
2015-08-16 06:59:58 +00:00
} ) . find ( "div" ) . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( false , type + " " + pos + " Click event fired." ) ;
2015-08-16 06:59:58 +00:00
} ) . on ( "focus" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( false , type + " " + pos + " Focus event fired." ) ;
2015-08-16 06:59:58 +00:00
} ) . end ( ) . appendTo ( "body" ) ;
2010-12-07 01:37:16 +00:00
2012-12-04 18:21:47 +00:00
div [ 0 ] . detachEvent = div [ 0 ] . removeEventListener = function ( t ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , type + " Outer " + t + " event unbound" ) ;
2010-01-24 02:20:19 +00:00
} ;
2010-12-07 01:37:16 +00:00
2012-12-04 18:21:47 +00:00
div [ 0 ] . firstChild . detachEvent = div [ 0 ] . firstChild . removeEventListener = function ( t ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , type + " Inner " + t + " event unbound" ) ;
2010-01-24 02:20:19 +00:00
} ;
2010-12-07 01:37:16 +00:00
2010-01-24 02:20:19 +00:00
return div ;
}
2015-08-16 06:59:58 +00:00
} ) ;
2010-12-27 19:43:52 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "jQuery.cleanData eliminates all private data (gh-2127)" , function ( assert ) {
assert . expect ( 3 ) ;
2015-03-09 16:03:43 +00:00
2020-03-16 20:49:29 +00:00
var div = jQuery ( "<div></div>" ) . appendTo ( "#qunit-fixture" ) ;
2015-03-09 16:03:43 +00:00
jQuery . _data ( div [ 0 ] , "gh-2127" , "testing" ) ;
2015-08-16 03:45:28 +00:00
assert . ok ( ! jQuery . isEmptyObject ( jQuery . _data ( div [ 0 ] ) ) , "Ensure some private data exists" ) ;
2015-03-09 16:03:43 +00:00
div . remove ( ) ;
2015-08-16 03:45:28 +00:00
assert . ok ( ! jQuery . hasData ( div [ 0 ] ) , "Removed element hasData should return false" ) ;
2015-07-19 00:47:31 +00:00
2015-08-16 03:45:28 +00:00
assert . ok ( jQuery . isEmptyObject ( jQuery . _data ( div [ 0 ] ) ) ,
2015-03-09 16:03:43 +00:00
"Private data is empty after node is removed" ) ;
div . remove ( ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-03-09 16:03:43 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "jQuery.cleanData eliminates all public data" , function ( assert ) {
2015-07-18 18:27:11 +00:00
assert . expect ( 3 ) ;
2015-07-19 00:47:31 +00:00
var key ,
2020-03-16 20:49:29 +00:00
div = jQuery ( "<div></div>" ) ;
2015-07-19 00:47:31 +00:00
div . data ( "some" , "data" ) ;
2015-08-16 03:45:28 +00:00
assert . ok ( ! jQuery . isEmptyObject ( jQuery . data ( div [ 0 ] ) ) , "Ensure some public data exists" ) ;
2015-07-19 00:47:31 +00:00
div . remove ( ) ;
2015-08-16 03:45:28 +00:00
assert . ok ( ! jQuery . hasData ( div [ 0 ] ) , "Removed element hasData should return false" ) ;
2015-07-19 00:47:31 +00:00
// Make sure the expando is gone
for ( key in div [ 0 ] ) {
if ( /^jQuery/ . test ( key ) ) {
2015-07-18 18:27:11 +00:00
assert . strictEqual ( div [ 0 ] [ key ] , undefined , "Expando was not removed when there was no more data" ) ;
2015-07-19 00:47:31 +00:00
}
}
2015-08-16 06:59:58 +00:00
} ) ;
2015-07-19 00:47:31 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "domManip plain-text caching (trac-6779)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2010-12-27 19:43:52 +00:00
// DOM manipulation fails if added text matches an Object method
2012-12-04 18:21:47 +00:00
var i ,
2020-03-16 20:49:29 +00:00
$f = jQuery ( "<div></div>" ) . appendTo ( "#qunit-fixture" ) ,
2010-12-27 19:43:52 +00:00
bad = [ "start-" , "toString" , "hasOwnProperty" , "append" , "here&there!" , "-end" ] ;
2012-12-04 18:21:47 +00:00
for ( i = 0 ; i < bad . length ; i ++ ) {
2010-12-27 19:43:52 +00:00
try {
2012-12-04 18:21:47 +00:00
$f . append ( bad [ i ] ) ;
2010-12-27 19:43:52 +00:00
}
2015-08-16 06:59:58 +00:00
catch ( e ) { }
2010-12-27 19:43:52 +00:00
}
2015-08-16 06:59:58 +00:00
assert . equal ( $f . text ( ) , bad . join ( "" ) , "Cached strings that match Object properties" ) ;
2010-12-27 19:43:52 +00:00
$f . remove ( ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2011-05-11 12:12:19 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "domManip executes scripts containing html comments or CDATA (trac-9221)" , function ( assert ) {
2012-12-04 18:21:47 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 3 ) ;
2011-04-30 14:42:36 +00:00
2015-04-10 19:57:18 +00:00
jQuery ( [
"<script type='text/javascript'>" ,
"<!--" ,
2019-02-18 18:02:38 +00:00
"QUnit.assert.ok( true, '<!-- handled' );" ,
2015-04-10 19:57:18 +00:00
"//-->" ,
"</script>"
] . join ( "\n" ) ) . appendTo ( "#qunit-fixture" ) ;
2021-07-19 17:04:23 +00:00
// This test requires XHTML mode as CDATA is not recognized in HTML.
// jQuery( [
// "<script type='text/javascript'>",
// "<![CDATA[",
// "QUnit.assert.ok( true, '<![CDATA[ handled' );",
// "//]]>",
// "</script>"
// ].join( "\n" ) ).appendTo( "#qunit-fixture" );
2015-04-10 19:57:18 +00:00
jQuery ( [
"<script type='text/javascript'>" ,
2021-07-19 17:04:23 +00:00
"<!--//--><![CDATA[//><!--" ,
"QUnit.assert.ok( true, '<!--//--><![CDATA[//><!-- (Drupal case) handled' );" ,
"//--><!]]>" ,
2015-04-10 19:57:18 +00:00
"</script>"
] . join ( "\n" ) ) . appendTo ( "#qunit-fixture" ) ;
2021-07-19 17:04:23 +00:00
// ES2015 in Annex B requires HTML-style comment delimiters (`<!--` & `-->`) to act as
// single-line comment delimiters; i.e. they should be treated as `//`.
// See gh-4904
2015-04-10 19:57:18 +00:00
jQuery ( [
"<script type='text/javascript'>" ,
2021-07-19 17:04:23 +00:00
"<!-- Same-line HTML comment" ,
"QUnit.assert.ok( true, '<!-- Same-line HTML comment' );" ,
"-->" ,
2015-04-10 19:57:18 +00:00
"</script>"
] . join ( "\n" ) ) . appendTo ( "#qunit-fixture" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-04-10 19:57:18 +00:00
2016-04-10 19:42:44 +00:00
testIframe (
2015-04-10 19:57:18 +00:00
"domManip tolerates window-valued document[0] in IE9/10 (trac-12266)" ,
"manipulation/iframe-denied.html" ,
2016-04-10 19:42:44 +00:00
function ( assert , jQuery , window , document , test ) {
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
assert . ok ( test . status , test . description ) ;
2015-04-10 19:57:18 +00:00
}
) ;
2011-06-15 15:14:52 +00:00
2016-04-10 19:42:44 +00:00
testIframe (
2015-11-06 23:36:38 +00:00
"domManip executes scripts in iframes in the iframes' context" ,
"manipulation/scripts-context.html" ,
2016-04-10 19:42:44 +00:00
function ( assert , framejQuery , frameWindow , frameDocument ) {
2015-11-06 23:36:38 +00:00
assert . expect ( 2 ) ;
2016-04-10 19:42:44 +00:00
jQuery ( frameDocument . body ) . append ( "<script>window.scriptTest = true;<\x2fscript>" ) ;
2015-11-06 23:36:38 +00:00
assert . ok ( ! window . scriptTest , "script executed in iframe context" ) ;
assert . ok ( frameWindow . scriptTest , "script executed in iframe context" ) ;
}
) ;
2020-02-10 18:17:22 +00:00
testIframe (
"domManip executes external scripts in iframes in the iframes' context" ,
"manipulation/scripts-context.html" ,
function ( assert , framejQuery , frameWindow , frameDocument ) {
assert . expect ( 2 ) ;
Globals . register ( "finishTest" ) ;
return new Promise ( function ( resolve ) {
window . finishTest = resolve ;
jQuery ( frameDocument . body ) . append (
"<script src='" + url ( "manipulation/set-global-scripttest.js" ) + "'></script>" ) ;
assert . ok ( ! window . scriptTest , "script executed in iframe context" ) ;
assert . ok ( frameWindow . scriptTest , "script executed in iframe context" ) ;
} ) ;
} ,
// The AJAX module is needed for jQuery._evalUrl.
QUnit [ jQuery . ajax ? "test" : "skip" ]
) ;
2020-09-22 15:30:18 +00:00
// We need to simulate cross-domain requests with the feature that
// both 127.0.0.1 and localhost point to the mock http server.
// Skip the the test if we are not in localhost but make sure we run
// it in Karma.
QUnit [
jQuery . ajax && ( window . _ _karma _ _ || location . hostname === "localhost" ) ?
"test" :
"skip"
] ( "jQuery.append with crossorigin attribute" , function ( assert ) {
assert . expect ( 1 ) ;
var done = assert . async ( ) ,
timeout ;
Globals . register ( "corsCallback" ) ;
window . corsCallback = function ( response ) {
assert . ok ( typeof response . headers . origin === "string" , "Origin header sent" ) ;
window . clearTimeout ( timeout ) ;
done ( ) ;
} ;
var src = baseURL + "mock.php?action=script&cors=1&callback=corsCallback" ;
src = src . replace ( "localhost" , "127.0.0.1" ) ;
var html = "<script type=\"text/javascript\" src=\"" + src + "\" crossorigin=\"anonymous\"><\/script>" ;
jQuery ( document . body ) . append ( html ) ;
timeout = window . setTimeout ( function ( ) {
assert . ok ( false , "Origin header should have been sent" ) ;
done ( ) ;
} , 2000 ) ;
} ) ;
2015-08-16 03:45:28 +00:00
QUnit . test ( "jQuery.clone - no exceptions for object elements #9587" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2011-06-15 15:14:52 +00:00
try {
2015-08-16 06:59:58 +00:00
jQuery ( "#no-clone-exception" ) . clone ( ) ;
2015-08-16 03:45:28 +00:00
assert . ok ( true , "cloned with no exceptions" ) ;
2015-08-16 06:59:58 +00:00
} catch ( e ) {
2015-08-16 03:45:28 +00:00
assert . ok ( false , e . message ) ;
2011-06-15 15:14:52 +00:00
}
2015-08-16 06:59:58 +00:00
} ) ;
2011-11-08 02:22:04 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Cloned, detached HTML5 elems (#10667,10670)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 7 ) ;
2011-11-08 02:22:04 +00:00
2012-12-04 18:21:47 +00:00
var $clone ,
$section = jQuery ( "<section>" ) . appendTo ( "#qunit-fixture" ) ;
2011-11-08 02:22:04 +00:00
// First clone
$clone = $section . clone ( ) ;
2017-05-19 20:28:54 +00:00
// This branch tests a known behavior in modern browsers that should never fail.
2013-08-26 22:54:13 +00:00
// Included for expected test count symmetry (expecting 1)
2015-08-16 03:45:28 +00:00
assert . equal ( $clone [ 0 ] . nodeName , "SECTION" , "detached clone nodeName matches 'SECTION'" ) ;
2011-11-08 02:22:04 +00:00
// Bind an event
2013-04-09 15:45:09 +00:00
$section . on ( "click" , function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "clone fired event" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2011-11-08 02:22:04 +00:00
// Second clone (will have an event bound)
$clone = $section . clone ( true ) ;
// Trigger an event from the first clone
2015-08-16 06:59:58 +00:00
$clone . trigger ( "click" ) ;
$clone . off ( "click" ) ;
2011-11-08 02:22:04 +00:00
// Add a child node with text to the original
2015-08-16 06:59:58 +00:00
$section . append ( "<p>Hello</p>" ) ;
2011-11-08 02:22:04 +00:00
// Third clone (will have child node and text)
$clone = $section . clone ( true ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( $clone . find ( "p" ) . text ( ) , "Hello" , "Assert text in child of clone" ) ;
2011-11-08 02:22:04 +00:00
// Trigger an event from the third clone
2015-08-16 06:59:58 +00:00
$clone . trigger ( "click" ) ;
$clone . off ( "click" ) ;
2011-11-08 02:22:04 +00:00
// Add attributes to copy
2015-08-16 06:59:58 +00:00
$section . attr ( {
2011-11-08 02:22:04 +00:00
"class" : "foo bar baz" ,
"title" : "This is a title"
2015-08-16 06:59:58 +00:00
} ) ;
2011-11-08 02:22:04 +00:00
// Fourth clone (will have newly added attributes)
$clone = $section . clone ( true ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( $clone . attr ( "class" ) , $section . attr ( "class" ) , "clone and element have same class attribute" ) ;
assert . equal ( $clone . attr ( "title" ) , $section . attr ( "title" ) , "clone and element have same title attribute" ) ;
2011-11-08 02:22:04 +00:00
// Remove the original
$section . remove ( ) ;
// Clone the clone
$section = $clone . clone ( true ) ;
// Remove the clone
$clone . remove ( ) ;
// Trigger an event from the clone of the clone
2015-08-16 06:59:58 +00:00
$section . trigger ( "click" ) ;
2011-11-08 02:22:04 +00:00
// Unbind any remaining events
2015-08-16 06:59:58 +00:00
$section . off ( "click" ) ;
$clone . off ( "click" ) ;
} ) ;
2011-11-08 05:05:33 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Guard against exceptions when clearing safeChildNodes" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 1 ) ;
2012-03-06 15:22:58 +00:00
var div ;
try {
2020-03-16 20:49:29 +00:00
div = jQuery ( "<div></div><hr/><code></code><b></b>" ) ;
2015-08-16 06:59:58 +00:00
} catch ( e ) { }
2012-03-06 15:22:58 +00:00
2015-08-16 03:45:28 +00:00
assert . ok ( div && div . jquery , "Created nodes safely, guarded against exceptions on safeChildNodes[ -1 ]" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-04-17 01:57:41 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Ensure oldIE creates a new set on appendTo (#8894)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 5 ) ;
2012-10-15 16:19:20 +00:00
2020-03-16 20:49:29 +00:00
assert . strictEqual ( jQuery ( "<div></div>" ) . clone ( ) . addClass ( "test" ) . appendTo ( "<div></div>" ) . end ( ) . end ( ) . hasClass ( "test" ) , false , "Check jQuery.fn.appendTo after jQuery.clone" ) ;
assert . strictEqual ( jQuery ( "<div></div>" ) . find ( "p" ) . end ( ) . addClass ( "test" ) . appendTo ( "<div></div>" ) . end ( ) . end ( ) . hasClass ( "test" ) , false , "Check jQuery.fn.appendTo after jQuery.fn.find" ) ;
assert . strictEqual ( jQuery ( "<div></div>" ) . text ( "test" ) . addClass ( "test" ) . appendTo ( "<div></div>" ) . end ( ) . end ( ) . hasClass ( "test" ) , false , "Check jQuery.fn.appendTo after jQuery.fn.text" ) ;
assert . strictEqual ( jQuery ( "<bdi></bdi>" ) . clone ( ) . addClass ( "test" ) . appendTo ( "<div></div>" ) . end ( ) . end ( ) . hasClass ( "test" ) , false , "Check jQuery.fn.appendTo after clone html5 element" ) ;
assert . strictEqual ( jQuery ( "<p></p>" ) . appendTo ( "<div></div>" ) . end ( ) . length , jQuery ( "<p>test</p>" ) . appendTo ( "<div></div>" ) . end ( ) . length , "Elements created with createElement and with createDocumentFragment should be treated alike" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-05-31 15:31:13 +00:00
2019-02-18 18:02:38 +00:00
QUnit . test ( "html() - script exceptions bubble (#11743)" , function ( assert ) {
assert . expect ( 2 ) ;
var done = assert . async ( ) ,
onerror = window . onerror ;
2012-12-05 02:50:22 +00:00
2015-08-16 06:59:58 +00:00
setTimeout ( function ( ) {
2013-11-29 08:15:05 +00:00
window . onerror = onerror ;
2012-05-31 15:31:13 +00:00
2019-02-18 18:02:38 +00:00
done ( ) ;
2013-11-29 08:15:05 +00:00
} , 1000 ) ;
2013-01-08 13:04:00 +00:00
2013-11-29 08:15:05 +00:00
window . onerror = function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "Exception thrown" ) ;
2013-01-08 13:04:00 +00:00
2013-11-29 08:15:05 +00:00
if ( jQuery . ajax ) {
window . onerror = function ( ) {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "Exception thrown in remote script" ) ;
2013-11-29 08:15:05 +00:00
} ;
2017-08-01 16:52:45 +00:00
jQuery ( "#qunit-fixture" ) . html ( "<script src='" + baseURL + "badcall.js'></script>" ) ;
2015-08-16 03:45:28 +00:00
assert . ok ( true , "Exception ignored" ) ;
2013-11-29 08:15:05 +00:00
} else {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "No jQuery.ajax" ) ;
2013-11-29 08:15:05 +00:00
}
} ;
jQuery ( "#qunit-fixture" ) . html ( "<script>undefined();</script>" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-07-26 02:23:24 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "checked state is cloned with clone()" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2012-07-26 02:23:24 +00:00
2015-08-16 06:59:58 +00:00
var elem = jQuery . parseHTML ( "<input type='checkbox' checked='checked'/>" ) [ 0 ] ;
2012-07-26 02:23:24 +00:00
elem . checked = false ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( elem ) . clone ( ) . attr ( "id" , "clone" ) [ 0 ] . checked , false , "Checked false state correctly cloned" ) ;
2012-10-16 14:17:14 +00:00
2015-08-16 06:59:58 +00:00
elem = jQuery . parseHTML ( "<input type='checkbox'/>" ) [ 0 ] ;
2012-07-26 02:23:24 +00:00
elem . checked = true ;
2015-08-16 06:59:58 +00:00
assert . equal ( jQuery ( elem ) . clone ( ) . attr ( "id" , "clone" ) [ 0 ] . checked , true , "Checked true state correctly cloned" ) ;
} ) ;
2012-08-23 01:23:50 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "manipulate mixed jQuery and text (#12384, #12346)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 2 ) ;
2012-08-28 21:00:12 +00:00
2015-08-16 06:59:58 +00:00
var div = jQuery ( "<div>a</div>" ) . append ( " " , jQuery ( "<span>b</span>" ) , " " , jQuery ( "<span>c</span>" ) ) ,
2012-12-04 18:21:47 +00:00
nbsp = String . fromCharCode ( 160 ) ;
2012-12-05 02:50:22 +00:00
2015-08-16 06:59:58 +00:00
assert . equal ( div . text ( ) , "a" + nbsp + "b" + nbsp + "c" , "Appending mixed jQuery with text nodes" ) ;
2012-08-28 21:00:12 +00:00
2015-08-16 06:59:58 +00:00
div = jQuery ( "<div><div></div></div>" )
. find ( "div" )
2012-12-04 18:21:47 +00:00
. after ( "<p>a</p>" , "<p>b</p>" )
2012-08-28 21:00:12 +00:00
. parent ( ) ;
2015-08-16 06:59:58 +00:00
assert . equal ( div . find ( "*" ) . length , 3 , "added 2 paragraphs after inner div" ) ;
} ) ;
2012-08-28 21:00:12 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "script evaluation (#11795)" , function ( assert ) {
2012-12-05 02:50:22 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 13 ) ;
2012-11-19 14:50:19 +00:00
var scriptsIn , scriptsOut ,
2015-08-16 06:59:58 +00:00
fixture = jQuery ( "#qunit-fixture" ) . empty ( ) ,
objGlobal = ( function ( ) {
2012-12-04 18:21:47 +00:00
return this ;
2015-08-16 06:59:58 +00:00
} ) ( ) ,
2012-11-19 14:50:19 +00:00
isOk = objGlobal . ok ,
notOk = function ( ) {
var args = arguments ;
2012-12-04 18:21:47 +00:00
args [ 0 ] = ! args [ 0 ] ;
2012-11-19 14:50:19 +00:00
return isOk . apply ( this , args ) ;
} ;
objGlobal . ok = notOk ;
2015-08-16 06:59:58 +00:00
scriptsIn = jQuery ( [
2019-02-18 18:02:38 +00:00
"<script type='something/else'>QUnit.assert.ok( false, 'evaluated: non-script' );</script>" ,
"<script type='text/javascript'>QUnit.assert.ok( true, 'evaluated: text/javascript' );</script>" ,
"<script type='text/ecmascript'>QUnit.assert.ok( true, 'evaluated: text/ecmascript' );</script>" ,
"<script>QUnit.assert.ok( true, 'evaluated: no type' );</script>" ,
2012-11-19 14:50:19 +00:00
"<div>" ,
2019-02-18 18:02:38 +00:00
"<script type='something/else'>QUnit.assert.ok( false, 'evaluated: inner non-script' );</script>" ,
"<script type='text/javascript'>QUnit.assert.ok( true, 'evaluated: inner text/javascript' );</script>" ,
"<script type='text/ecmascript'>QUnit.assert.ok( true, 'evaluated: inner text/ecmascript' );</script>" ,
"<script>QUnit.assert.ok( true, 'evaluated: inner no type' );</script>" ,
2012-11-19 14:50:19 +00:00
"</div>"
2015-08-16 06:59:58 +00:00
] . join ( "" ) ) ;
2020-03-16 20:49:29 +00:00
scriptsIn . appendTo ( jQuery ( "<div class='detached'></div>" ) ) ;
2012-11-19 14:50:19 +00:00
objGlobal . ok = isOk ;
2015-08-16 06:59:58 +00:00
scriptsOut = fixture . append ( scriptsIn ) . find ( "script" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( scriptsOut [ 0 ] . type , "something/else" , "Non-evaluated type." ) ;
assert . equal ( scriptsOut [ 1 ] . type , "text/javascript" , "Evaluated type." ) ;
2015-08-16 06:59:58 +00:00
assert . deepEqual ( scriptsOut . get ( ) , fixture . find ( "script" ) . get ( ) , "All script tags remain." ) ;
2012-11-19 14:50:19 +00:00
objGlobal . ok = notOk ;
2015-08-16 06:59:58 +00:00
scriptsOut = scriptsOut . add ( scriptsOut . clone ( ) ) . appendTo ( fixture . find ( "div" ) ) ;
assert . deepEqual ( fixture . find ( "div script" ) . get ( ) , scriptsOut . get ( ) , "Scripts cloned without reevaluation" ) ;
2012-11-19 14:50:19 +00:00
fixture . append ( scriptsOut . detach ( ) ) ;
2015-08-16 06:59:58 +00:00
assert . deepEqual ( fixture . children ( "script" ) . get ( ) , scriptsOut . get ( ) , "Scripts detached without reevaluation" ) ;
2012-11-19 14:50:19 +00:00
objGlobal . ok = isOk ;
2012-12-02 05:14:25 +00:00
if ( jQuery . ajax ) {
2015-08-16 06:59:58 +00:00
Globals . register ( "testBar" ) ;
2020-03-16 20:49:29 +00:00
jQuery ( "#qunit-fixture" ) . append ( "<script src='" + url ( "mock.php?action=testbar" ) + "'></script>" ) ;
2016-05-10 09:12:28 +00:00
assert . strictEqual ( window . testBar , "bar" , "Global script evaluation" ) ;
2012-12-02 05:14:25 +00:00
} else {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "No jQuery.ajax" ) ;
assert . ok ( true , "No jQuery.ajax" ) ;
2012-12-02 05:14:25 +00:00
}
2015-08-16 06:59:58 +00:00
} ) ;
2012-12-02 05:14:25 +00:00
2020-01-07 22:59:08 +00:00
QUnit [ jQuery . ajax ? "test" : "skip" ] ( "jQuery._evalUrl (#12838)" , function ( assert ) {
2012-12-02 05:14:25 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 5 ) ;
2012-12-02 05:14:25 +00:00
var message , expectedArgument ,
ajax = jQuery . ajax ,
evalUrl = jQuery . _evalUrl ;
message = "jQuery.ajax implementation" ;
expectedArgument = 1 ;
jQuery . ajax = function ( input ) {
2015-08-16 03:45:28 +00:00
assert . equal ( ( input . url || input ) . slice ( - 1 ) , expectedArgument , message ) ;
2012-12-02 05:14:25 +00:00
expectedArgument ++ ;
} ;
2020-03-16 20:49:29 +00:00
jQuery ( "#qunit-fixture" ) . append ( "<script src='1'></script><script src='2'></script>" ) ;
2015-08-16 03:45:28 +00:00
assert . equal ( expectedArgument , 3 , "synchronous execution" ) ;
2012-12-02 05:14:25 +00:00
message = "custom implementation" ;
expectedArgument = 3 ;
jQuery . _evalUrl = jQuery . ajax ;
jQuery . ajax = function ( options ) {
2015-08-16 03:45:28 +00:00
assert . strictEqual ( options , { } , "Unexpected call to jQuery.ajax" ) ;
2012-12-02 05:14:25 +00:00
} ;
2020-03-16 20:49:29 +00:00
jQuery ( "#qunit-fixture" ) . append ( "<script src='3'></script><script src='4'></script>" ) ;
2012-12-02 05:14:25 +00:00
jQuery . ajax = ajax ;
jQuery . _evalUrl = evalUrl ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-11-19 14:50:19 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "jQuery.htmlPrefilter (gh-1747)" , function ( assert ) {
2015-04-10 19:57:18 +00:00
assert . expect ( 5 ) ;
var expectedArgument ,
invocations = 0 ,
2015-08-16 03:45:28 +00:00
done = assert . async ( ) ,
2015-04-10 19:57:18 +00:00
htmlPrefilter = jQuery . htmlPrefilter ,
2020-03-16 20:49:29 +00:00
fixture = jQuery ( "<div></div>" ) . appendTo ( "#qunit-fixture" ) ,
2015-08-16 03:45:28 +00:00
poison = "<script>jQuery.htmlPrefilter.assert.ok( false, 'script not executed' );</script>" ;
2015-04-10 19:57:18 +00:00
jQuery . htmlPrefilter = function ( html ) {
invocations ++ ;
assert . equal ( html , expectedArgument , "Expected input" ) ;
// Remove <script> and <del> elements
return htmlPrefilter . apply ( this , arguments )
. replace ( /<(script|del)(?=[\s>])[\w\W]*?<\/\1\s*>/ig , "" ) ;
} ;
jQuery . htmlPrefilter . assert = assert ;
expectedArgument = "A-" + poison + "B-" + poison + poison + "C-" ;
fixture . html ( expectedArgument ) ;
2020-03-16 20:49:29 +00:00
expectedArgument = "D-" + poison + "E-" + "<del></del><div>" + poison + poison + "</div>" + "F-" ;
2015-04-10 19:57:18 +00:00
fixture . append ( expectedArgument ) ;
expectedArgument = poison ;
fixture . find ( "div" ) . replaceWith ( expectedArgument ) ;
assert . equal ( invocations , 3 , "htmlPrefilter invoked for all DOM manipulations" ) ;
assert . equal ( fixture . html ( ) , "A-B-C-D-E-F-" , "htmlPrefilter modified HTML" ) ;
// Allow asynchronous script execution to generate assertions
setTimeout ( function ( ) {
jQuery . htmlPrefilter = htmlPrefilter ;
done ( ) ;
} , 100 ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-04-10 19:57:18 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "insertAfter, insertBefore, etc do not work when destination is original element. Element is removed (#4087)" , function ( assert ) {
2012-12-10 21:12:54 +00:00
2015-08-16 03:45:28 +00:00
assert . expect ( 10 ) ;
2012-12-10 21:12:54 +00:00
var elems ;
2015-08-16 06:59:58 +00:00
jQuery . each ( [
2012-12-10 21:12:54 +00:00
"appendTo" ,
"prependTo" ,
"insertBefore" ,
"insertAfter" ,
"replaceAll"
] , function ( index , name ) {
elems = jQuery ( [
"<ul id='test4087-complex'><li class='test4087'><div>c1</div>h1</li><li><div>c2</div>h2</li></ul>" ,
"<div id='test4087-simple'><div class='test4087-1'>1<div class='test4087-2'>2</div><div class='test4087-3'>3</div></div></div>" ,
"<div id='test4087-multiple'><div class='test4087-multiple'>1</div><div class='test4087-multiple'>2</div></div>"
2015-08-16 06:59:58 +00:00
] . join ( "" ) ) . appendTo ( "#qunit-fixture" ) ;
2012-12-10 21:12:54 +00:00
2015-11-29 17:41:37 +00:00
// complex case based on https://jsfiddle.net/pbramos/gZ7vB/
2015-08-16 06:59:58 +00:00
jQuery ( "#test4087-complex div" ) [ name ] ( "#test4087-complex li:last-child div:last-child" ) ;
assert . equal ( jQuery ( "#test4087-complex li:last-child div" ) . length , name === "replaceAll" ? 1 : 2 , name + " a node to itself, complex case." ) ;
2012-12-10 21:12:54 +00:00
// simple case
2015-08-16 06:59:58 +00:00
jQuery ( ".test4087-1" ) [ name ] ( ".test4087-1" ) ;
assert . equal ( jQuery ( ".test4087-1" ) . length , 1 , name + " a node to itself, simple case." ) ;
2012-12-10 21:12:54 +00:00
// clean for next test
2015-08-16 06:59:58 +00:00
jQuery ( "#test4087-complex" ) . remove ( ) ;
jQuery ( "#test4087-simple" ) . remove ( ) ;
jQuery ( "#test4087-multiple" ) . remove ( ) ;
} ) ;
} ) ;
2012-12-19 23:52:08 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Index for function argument should be received (#13094)" , function ( assert ) {
assert . expect ( 2 ) ;
2015-07-29 15:10:04 +00:00
2012-12-24 00:47:13 +00:00
var i = 0 ;
2012-12-19 23:52:08 +00:00
2020-03-16 20:49:29 +00:00
jQuery ( "<div></div><div></div>" ) . before ( function ( index ) {
2015-08-16 03:45:28 +00:00
assert . equal ( index , i ++ , "Index should be correct" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2012-12-19 23:26:55 +00:00
2015-08-16 06:59:58 +00:00
} ) ;
2012-12-20 16:50:00 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Make sure jQuery.fn.remove can work on elements in documentFragment" , function ( assert ) {
assert . expect ( 1 ) ;
2015-07-29 15:10:04 +00:00
2012-12-20 16:50:00 +00:00
var fragment = document . createDocumentFragment ( ) ,
2015-08-16 06:59:58 +00:00
div = fragment . appendChild ( document . createElement ( "div" ) ) ;
2012-12-20 16:50:00 +00:00
2012-12-23 16:51:07 +00:00
jQuery ( div ) . remove ( ) ;
2012-12-20 16:50:00 +00:00
2015-08-16 03:45:28 +00:00
assert . equal ( fragment . childNodes . length , 0 , "div element was removed from documentFragment" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2013-01-16 18:07:53 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Make sure specific elements with content created correctly (#13232)" , function ( assert ) {
assert . expect ( 20 ) ;
2015-07-29 15:10:04 +00:00
2013-01-16 18:07:53 +00:00
var results = [ ] ,
args = [ ] ,
elems = {
thead : "<tr><td>thead</td></tr>" ,
tbody : "<tr><td>tbody</td></tr>" ,
tfoot : "<tr><td>tfoot</td></tr>" ,
2020-03-16 20:49:29 +00:00
colgroup : "<col span='5'></col>" ,
2013-01-16 18:07:53 +00:00
caption : "caption" ,
tr : "<td>tr</td>" ,
th : "th" ,
td : "<div>td</div>" ,
optgroup : "<option>optgroup</option>" ,
option : "option"
} ;
jQuery . each ( elems , function ( name , value ) {
var html = "<" + name + ">" + value + "</" + name + ">" ;
2019-04-29 20:56:09 +00:00
assert . strictEqual (
jQuery . parseHTML ( "<" + name + ">" + value + "</" + name + ">" ) [ 0 ] . nodeName . toLowerCase ( ) ,
name ,
name + " is created correctly"
) ;
2013-01-16 18:07:53 +00:00
results . push ( name ) ;
args . push ( html ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2013-01-16 18:07:53 +00:00
2020-03-16 20:49:29 +00:00
jQuery . fn . append . apply ( jQuery ( "<div></div>" ) , args ) . children ( ) . each ( function ( i ) {
2019-04-29 20:56:09 +00:00
assert . strictEqual ( this . nodeName . toLowerCase ( ) , results [ i ] ) ;
2015-08-16 06:59:58 +00:00
} ) ;
} ) ;
2013-04-24 18:15:41 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Validate creation of multiple quantities of certain elements (#13818)" , function ( assert ) {
2020-03-16 20:49:29 +00:00
assert . expect ( 22 ) ;
2015-07-29 15:10:04 +00:00
2013-04-24 18:15:41 +00:00
var tags = [ "thead" , "tbody" , "tfoot" , "colgroup" , "col" , "caption" , "tr" , "th" , "td" , "optgroup" , "option" ] ;
jQuery . each ( tags , function ( index , tag ) {
2020-03-16 20:49:29 +00:00
jQuery ( "<" + tag + "></" + tag + "><" + tag + "></" + tag + ">" ) . each ( function ( ) {
assert . ok ( this . nodeName . toLowerCase ( ) === tag , tag + " elements created correctly" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
} ) ;
} ) ;
2014-11-28 06:09:29 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Make sure tr element will be appended to tbody element of table when present" , function ( assert ) {
assert . expect ( 1 ) ;
2015-01-21 18:47:03 +00:00
var html ,
table = document . createElement ( "table" ) ;
table . appendChild ( document . createElement ( "tbody" ) ) ;
document . getElementById ( "qunit-fixture" ) . appendChild ( table ) ;
jQuery ( table ) . append ( "<tr><td>test</td></tr>" ) ;
// Lowercase and replace spaces to remove possible browser inconsistencies
html = table . innerHTML . toLowerCase ( ) . replace ( /\s/g , "" ) ;
2015-08-16 03:45:28 +00:00
assert . strictEqual ( html , "<tbody><tr><td>test</td></tr></tbody>" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-01-21 18:47:03 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Make sure tr elements will be appended to tbody element of table when present" , function ( assert ) {
assert . expect ( 1 ) ;
2015-01-21 18:47:03 +00:00
var html ,
table = document . createElement ( "table" ) ;
table . appendChild ( document . createElement ( "tbody" ) ) ;
document . getElementById ( "qunit-fixture" ) . appendChild ( table ) ;
jQuery ( table ) . append ( "<tr><td>1</td></tr><tr><td>2</td></tr>" ) ;
// Lowercase and replace spaces to remove possible browser inconsistencies
html = table . innerHTML . toLowerCase ( ) . replace ( /\s/g , "" ) ;
2015-08-16 03:45:28 +00:00
assert . strictEqual ( html , "<tbody><tr><td>1</td></tr><tr><td>2</td></tr></tbody>" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-01-21 18:47:03 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Make sure tfoot element will not be appended to tbody element of table when present" , function ( assert ) {
assert . expect ( 1 ) ;
2015-01-21 18:47:03 +00:00
var html ,
table = document . createElement ( "table" ) ;
table . appendChild ( document . createElement ( "tbody" ) ) ;
document . getElementById ( "qunit-fixture" ) . appendChild ( table ) ;
2020-03-16 20:49:29 +00:00
jQuery ( table ) . append ( "<tfoot></tfoot>" ) ;
2015-01-21 18:47:03 +00:00
// Lowercase and replace spaces to remove possible browser inconsistencies
html = table . innerHTML . toLowerCase ( ) . replace ( /\s/g , "" ) ;
2015-08-16 03:45:28 +00:00
assert . strictEqual ( html , "<tbody></tbody><tfoot></tfoot>" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-01-21 18:47:03 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Make sure document fragment will be appended to tbody element of table when present" , function ( assert ) {
assert . expect ( 1 ) ;
2015-01-21 18:47:03 +00:00
var html ,
fragment = document . createDocumentFragment ( ) ,
table = document . createElement ( "table" ) ,
tr = document . createElement ( "tr" ) ,
td = document . createElement ( "td" ) ;
table . appendChild ( document . createElement ( "tbody" ) ) ;
document . getElementById ( "qunit-fixture" ) . appendChild ( table ) ;
fragment . appendChild ( tr ) ;
tr . appendChild ( td ) ;
td . innerHTML = "test" ;
jQuery ( table ) . append ( fragment ) ;
// Lowercase and replace spaces to remove possible browser inconsistencies
html = table . innerHTML . toLowerCase ( ) . replace ( /\s/g , "" ) ;
2015-08-16 03:45:28 +00:00
assert . strictEqual ( html , "<tbody><tr><td>test</td></tr></tbody>" ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-01-21 18:47:03 +00:00
2015-08-16 03:45:28 +00:00
QUnit . test ( "Make sure col element is appended correctly" , function ( assert ) {
assert . expect ( 1 ) ;
2015-01-22 23:34:29 +00:00
var table = jQuery ( "<table cellpadding='0'><tr><td>test</td></tr></table>" ) ;
jQuery ( table ) . appendTo ( "#qunit-fixture" ) ;
2020-03-16 20:49:29 +00:00
jQuery ( "<col width='150'></col>" ) . prependTo ( table ) ;
2015-01-22 23:34:29 +00:00
2015-08-16 03:45:28 +00:00
assert . strictEqual ( table . find ( "td" ) . width ( ) , 150 ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2015-01-22 23:34:29 +00:00
2017-01-09 19:37:12 +00:00
QUnit . test ( "Make sure tr is not appended to the wrong tbody (gh-3439)" , function ( assert ) {
assert . expect ( 1 ) ;
var htmlOut ,
htmlIn =
"<thead><tr><td>" +
"<table><tbody><tr><td>nested</td></tr></tbody></table>" +
"</td></tr></thead>" ,
newRow = "<tr><td>added</td></tr>" ,
htmlExpected = htmlIn . replace ( "</thead>" , "</thead>" + newRow ) ,
2020-03-16 20:49:29 +00:00
table = supportjQuery ( "<table></table>" ) . html ( htmlIn ) . appendTo ( "#qunit-fixture" ) [ 0 ] ;
2017-01-09 19:37:12 +00:00
jQuery ( table ) . append ( newRow ) ;
// Lowercase and replace spaces to remove possible browser inconsistencies
htmlOut = table . innerHTML . toLowerCase ( ) . replace ( /\s/g , "" ) ;
assert . strictEqual ( htmlOut , htmlExpected ) ;
} ) ;
2018-07-13 04:35:08 +00:00
QUnit . test ( "Make sure tags with single-character names are found (gh-4124)" , function ( assert ) {
assert . expect ( 1 ) ;
var htmlOut ,
htmlIn = "<p>foo<!--<td>--></p>" ,
2020-03-16 20:49:29 +00:00
$el = jQuery ( "<div></div>" ) ;
2018-07-13 04:35:08 +00:00
$el . html ( htmlIn ) ;
// Lowercase and replace spaces to remove possible browser inconsistencies
htmlOut = $el [ 0 ] . innerHTML . toLowerCase ( ) . replace ( /\s/g , "" ) ;
assert . strictEqual ( htmlOut , htmlIn ) ;
} ) ;
2020-01-07 22:59:08 +00:00
// The AJAX module is needed for jQuery._evalUrl.
QUnit [ jQuery . ajax ? "test" : "skip" ] ( "Insert script with data-URI (gh-1887)" , function ( assert ) {
2019-02-18 18:02:38 +00:00
assert . expect ( 1 ) ;
2019-04-29 20:56:09 +00:00
2014-11-28 06:09:29 +00:00
Globals . register ( "testFoo" ) ;
2014-12-07 10:01:16 +00:00
Globals . register ( "testSrcFoo" ) ;
var script = document . createElement ( "script" ) ,
2015-08-16 03:45:28 +00:00
fixture = document . getElementById ( "qunit-fixture" ) ,
done = assert . async ( ) ;
2014-12-07 10:01:16 +00:00
script . src = "data:text/javascript,testSrcFoo = 'foo';" ;
fixture . appendChild ( script ) ;
jQuery ( fixture ) . append ( "<script src=\"data:text/javascript,testFoo = 'foo';\"></script>" ) ;
2015-08-16 06:59:58 +00:00
setTimeout ( function ( ) {
2016-05-10 09:12:28 +00:00
if ( window . testSrcFoo === "foo" ) {
assert . strictEqual ( window . testFoo , window . testSrcFoo , "data-URI script executed" ) ;
2014-12-07 10:01:16 +00:00
} else {
2015-08-16 03:45:28 +00:00
assert . ok ( true , "data-URI script is not supported by this environment" ) ;
2014-12-07 10:01:16 +00:00
}
2015-08-16 03:45:28 +00:00
done ( ) ;
2015-01-15 02:41:27 +00:00
} , 100 ) ;
2015-08-16 06:59:58 +00:00
} ) ;
2018-12-12 16:21:24 +00:00
2019-02-18 18:02:38 +00:00
QUnit . test ( "Ignore content from unsuccessful responses (gh-4126)" , function ( assert ) {
assert . expect ( 1 ) ;
2018-12-12 16:21:24 +00:00
var globalEval = jQuery . globalEval ;
jQuery . globalEval = function ( code ) {
assert . ok ( false , "no attempt to evaluate code from an unsuccessful response" ) ;
} ;
try {
jQuery ( "#qunit-fixture" ) . append (
2020-03-16 20:49:29 +00:00
"<script src='" + url ( "mock.php?action=error" ) + "'></script>" ) ;
2018-12-12 16:21:24 +00:00
assert . ok ( true , "no error thrown from embedding script with unsuccessful-response src" ) ;
} catch ( e ) {
throw e ;
} finally {
jQuery . globalEval = globalEval ;
}
} ) ;
2019-01-14 18:29:54 +00:00
testIframe (
"Check if CSP nonce is preserved" ,
"mock.php?action=cspNonce" ,
function ( assert , jQuery , window , document ) {
var done = assert . async ( ) ;
assert . expect ( 1 ) ;
supportjQuery . get ( baseURL + "support/csp.log" ) . done ( function ( data ) {
assert . equal ( data , "" , "No log request should be sent" ) ;
supportjQuery . get ( baseURL + "mock.php?action=cspClean" ) . done ( done ) ;
} ) ;
2020-09-22 15:49:28 +00:00
}
2019-03-19 21:40:30 +00:00
) ;
testIframe (
2019-04-29 20:56:09 +00:00
"Check if CSP nonce is preserved for external scripts with src attribute" ,
"mock.php?action=cspNonce&test=external" ,
function ( assert , jQuery , window , document ) {
var done = assert . async ( ) ;
assert . expect ( 1 ) ;
supportjQuery . get ( baseURL + "support/csp.log" ) . done ( function ( data ) {
assert . equal ( data , "" , "No log request should be sent" ) ;
supportjQuery . get ( baseURL + "mock.php?action=cspClean" ) . done ( done ) ;
} ) ;
} ,
2020-01-07 22:59:08 +00:00
// The AJAX module is needed for jQuery._evalUrl.
2020-09-22 15:49:28 +00:00
QUnit [ jQuery . ajax ? "test" : "skip" ]
2019-01-14 18:29:54 +00:00
) ;
2019-01-21 17:42:39 +00:00
testIframe (
"jQuery.globalEval supports nonce" ,
"mock.php?action=cspNonce&test=globaleval" ,
function ( assert , jQuery , window , document ) {
var done = assert . async ( ) ;
assert . expect ( 1 ) ;
supportjQuery . get ( baseURL + "support/csp.log" ) . done ( function ( data ) {
assert . equal ( data , "" , "No log request should be sent" ) ;
supportjQuery . get ( baseURL + "mock.php?action=cspClean" ) . done ( done ) ;
} ) ;
2020-09-22 15:49:28 +00:00
}
2019-01-21 17:42:39 +00:00
) ;
2020-04-29 14:39:04 +00:00
QUnit . test ( "Sanitized HTML doesn't get unsanitized" , function ( assert ) {
var container ,
counter = 0 ,
2020-04-30 19:25:29 +00:00
oldIos = /iphone os (?:8|9|10|11|12)_/i . test ( navigator . userAgent ) ,
assertCount = oldIos ? 12 : 13 ,
2020-04-29 14:39:04 +00:00
done = assert . async ( assertCount ) ;
assert . expect ( assertCount ) ;
Globals . register ( "xss" ) ;
window . xss = sinon . spy ( ) ;
container = jQuery ( "<div></div>" ) ;
container . appendTo ( "#qunit-fixture" ) ;
function test ( htmlString ) {
var currCounter = counter ,
div = jQuery ( "<div></div>" ) ;
counter ++ ;
div . appendTo ( container ) ;
div . html ( htmlString ) ;
setTimeout ( function ( ) {
assert . ok ( window . xss . withArgs ( currCounter ) . notCalled ,
"Insecure code wasn't executed, input: " + htmlString ) ;
done ( ) ;
} , 1000 ) ;
}
// Note: below test cases need to invoke the xss function with consecutive
// decimal parameters for the assertion messages to be correct.
// Thanks to Masato Kinugawa from Cure53 for providing the following test cases.
test ( "<img alt=\"<x\" title=\"/><img src=url404 onerror=xss(0)>\">" ) ;
test ( "<img alt=\"\n<x\" title=\"/>\n<img src=url404 onerror=xss(1)>\">" ) ;
test ( "<style><style/><img src=url404 onerror=xss(2)>" ) ;
test ( "<xmp><xmp/><img src=url404 onerror=xss(3)>" ) ;
test ( "<title><title /><img src=url404 onerror=xss(4)>" ) ;
test ( "<iframe><iframe/><img src=url404 onerror=xss(5)>" ) ;
test ( "<noframes><noframes/><img src=url404 onerror=xss(6)>" ) ;
2020-04-30 19:25:29 +00:00
test ( "<noscript><noscript/><img src=url404 onerror=xss(7)>" ) ;
test ( "<foo\" alt=\"\" title=\"/><img src=url404 onerror=xss(8)>\">" ) ;
test ( "<img alt=\"<x\" title=\"\" src=\"/><img src=url404 onerror=xss(9)>\">" ) ;
test ( "<noscript/><img src=url404 onerror=xss(10)>" ) ;
test ( "<option><style></option></select><img src=url404 onerror=xss(11)></style>" ) ;
// Support: iOS 8 - 12 only.
// Old iOS parses `<noembed>` tags differently, executing this code. This is no
// different to native behavior on that OS, though, so just accept it.
if ( ! oldIos ) {
test ( "<noembed><noembed/><img src=url404 onerror=xss(12)>" ) ;
}
2020-04-29 14:39:04 +00:00
} ) ;
2020-06-10 14:13:22 +00:00
QUnit . test ( "Works with invalid attempts to close the table wrapper" , function ( assert ) {
assert . expect ( 3 ) ;
// This test case attempts to close the tags which wrap input
// based on matching done in wrapMap which should be ignored.
var elem = jQuery ( "<td></td></tr></tbody></table><td></td>" ) ;
assert . strictEqual ( elem . length , 2 , "Two elements created" ) ;
assert . strictEqual ( elem [ 0 ] . nodeName . toLowerCase ( ) , "td" , "First element is td" ) ;
assert . strictEqual ( elem [ 1 ] . nodeName . toLowerCase ( ) , "td" , "Second element is td" ) ;
} ) ;
2021-09-30 14:00:24 +00:00
// Test trustedTypes support in browsers where they're supported (currently Chrome 83+).
// Browsers with no TrustedHTML support still run tests on object wrappers with
// a proper `toString` function.
testIframe (
"Basic TrustedHTML support (gh-4409)" ,
"mock.php?action=trustedHtml" ,
function ( assert , jQuery , window , document , test ) {
assert . expect ( 5 ) ;
test . forEach ( function ( result ) {
assert . deepEqual ( result . actual , result . expected , result . message ) ;
} ) ;
}
) ;