forked from jquery/jquery-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanipulation.js
60 lines (46 loc) · 2.04 KB
/
manipulation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"use strict";
QUnit.module( "manipulation" );
QUnit.test( "Improperly closed elements", function( assert ) {
assert.expect( 4 );
var oldWindowAlert = window.alert;
window.alert = function() {
assert.notOk( "Called alert with " + arguments );
};
jQuery.migrateEnablePatches( "self-closed-tags" );
expectWarning( assert, "Elements not self-closable nested wrong", 4, function() {
jQuery( "<div><p/><span/></div>" );
jQuery( "<blockquote><p class='bad' /><span/></blockquote>" );
jQuery( "<div />" ).append( "<div data-borked='y'><span/> <p/></div>" );
jQuery( "<script /><div class=afterscript/>" );
} );
expectNoWarning( assert, "Script doesn't run in processed strings", function() {
jQuery( "<script>alert( 'YOU SHOULD NOT SEE THIS ALERT' )</script>" );
jQuery( "<div>" ).append( "<script src='YOU-SHOULD-NOT-SEE-THIS.SCRIPT'></script>" );
jQuery( "<script>alert( 'YOU SHOULD NOT SEE THIS CONSOLE' )</script>" );
} );
expectNoWarning( assert, "Elements not self-closable but tolerable", function() {
jQuery( "<div class=wonky />" );
jQuery( "<p style='width: 2%' />" );
jQuery( "<p />" ).append( "<span aria-label='hello' />" );
} );
expectNoWarning( assert, "Bare elements", function() {
jQuery( "<p/>" ).append( "<strong>" );
jQuery( "<abbr />" );
jQuery( "<head />" );
} );
window.alert = oldWindowAlert;
} );
QUnit.test( "jQuery.UNSAFE_restoreLegacyHtmlPrefilter (deprecated)", function( assert ) {
assert.expect( 5 );
jQuery.UNSAFE_restoreLegacyHtmlPrefilter();
var warns = jQuery.migrateWarnings,
elem = jQuery( "<div/><span/>" ),
childCount = elem.length,
firstNodeName = elem[ 0 ] && elem[ 0 ].nodeName.toLowerCase(),
secondNodeName = elem[ 1 ] && elem[ 1 ].nodeName.toLowerCase();
assert.strictEqual( childCount, 2, "Proper child count" );
assert.strictEqual( firstNodeName, "div", "Proper first element" );
assert.strictEqual( secondNodeName, "span", "Proper second element" );
assert.equal( warns.length, 1, "Proper warning length" );
assert.ok( warns[ 0 ].indexOf( "HTML tags" ) >= 0, warns[ 0 ] );
} );