1 QUnit.module( "basic", { afterEach: moduleTeardown } );
3 if ( includesModule( "ajax" ) ) {
4 QUnit.test( "ajax", function( assert ) {
7 var done = assert.async( 3 );
11 url: url( "mock.php?action=name&name=foo" ),
12 success: function( msg ) {
13 assert.strictEqual( msg, "bar", "Check for GET" );
20 url: url( "mock.php?action=name" ),
22 success: function( msg ) {
23 assert.strictEqual( msg, "pan", "Check for POST" );
28 jQuery( "#first" ).load( url( "name.html" ), function() {
29 assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ),
30 "Check if content was injected into the DOM" );
36 if ( includesModule( "attributes" ) ) {
37 QUnit.test( "attributes", function( assert ) {
40 var a = jQuery( "<a></a>" ).appendTo( "#qunit-fixture" ),
41 input = jQuery( "<input/>" ).appendTo( "#qunit-fixture" );
43 assert.strictEqual( a.attr( "foo", "bar" ).attr( "foo" ), "bar", ".attr getter/setter" );
44 assert.strictEqual( a.removeAttr( "foo" ).attr( "foo" ), undefined, ".removeAttr" );
45 assert.strictEqual( a.prop( "href", "#5" ).prop( "href" ),
46 location.href.replace( /\#.*$/, "" ) + "#5",
47 ".prop getter/setter" );
49 a.addClass( "abc def ghj" ).removeClass( "def ghj" );
50 assert.strictEqual( a.hasClass( "abc" ), true, ".(add|remove|has)Class, class present" );
51 assert.strictEqual( a.hasClass( "def" ), false, ".(add|remove|has)Class, class missing" );
53 assert.strictEqual( input.val( "xyz" ).val(), "xyz", ".val getter/setter" );
57 if ( includesModule( "css" ) ) {
58 QUnit.test( "css", function( assert ) {
61 var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" );
63 assert.strictEqual( div.css( "width", "50px" ).css( "width" ), "50px", ".css getter/setter" );
67 if ( includesModule( "css" ) ) {
68 QUnit.test( "show/hide", function( assert ) {
71 var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" );
74 assert.strictEqual( div.css( "display" ), "none", "div hidden" );
76 assert.strictEqual( div.css( "display" ), "block", "div shown" );
80 QUnit.test( "core", function( assert ) {
83 var elem = jQuery( "<div></div><span></span>" );
85 assert.strictEqual( elem.length, 2, "Correct number of elements" );
87 assert.ok( jQuery.isPlainObject( { "a": 2 } ), "jQuery.isPlainObject(object)" );
88 assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" );
90 assert.ok( jQuery.isXMLDoc( jQuery.parseXML(
91 "<?xml version='1.0' encoding='UTF-8'?><foo bar='baz'></foo>"
92 ) ), "jQuery.isXMLDoc" );
94 assert.strictEqual( jQuery.inArray( 3, [ "a", 6, false, 3, {} ] ), 3, "jQuery.inArray - true" );
96 jQuery.inArray( 3, [ "a", 6, false, "3", {} ] ),
98 "jQuery.inArray - false"
101 assert.strictEqual( elem.get( 1 ), elem[ 1 ], ".get" );
102 assert.strictEqual( elem.first()[ 0 ], elem[ 0 ], ".first" );
103 assert.strictEqual( elem.last()[ 0 ], elem[ 1 ], ".last" );
105 assert.deepEqual( jQuery.map( [ "a", "b", "c" ], function( v, k ) {
107 } ), [ "0a", "1b", "2c" ], "jQuery.map" );
109 assert.deepEqual( jQuery.merge( [ 1, 2 ], [ "a", "b" ] ), [ 1, 2, "a", "b" ], "jQuery.merge" );
111 assert.deepEqual( jQuery.grep( [ 1, 2, 3 ], function( value ) {
112 return value % 2 !== 0;
113 } ), [ 1, 3 ], "jQuery.grep" );
115 assert.deepEqual( jQuery.extend( { a: 2 }, { b: 3 } ), { a: 2, b: 3 }, "jQuery.extend" );
117 jQuery.each( [ 0, 2 ], function( k, v ) {
118 assert.strictEqual( k * 2, v, "jQuery.each" );
121 assert.deepEqual( jQuery.makeArray( { 0: "a", 1: "b", 2: "c", length: 3 } ),
122 [ "a", "b", "c" ], "jQuery.makeArray" );
124 assert.strictEqual( jQuery.parseHTML( "<div></div><span></span>" ).length,
125 2, "jQuery.parseHTML" );
128 if ( includesModule( "data" ) ) {
129 QUnit.test( "data", function( assert ) {
132 var elem = jQuery( "<div data-c='d'></div>" ).appendTo( "#qunit-fixture" );
134 assert.ok( !jQuery.hasData( elem[ 0 ] ), "jQuery.hasData - false" );
135 assert.strictEqual( elem.data( "a", "b" ).data( "a" ), "b", ".data getter/setter" );
136 assert.strictEqual( elem.data( "c" ), "d", ".data from data-* attributes" );
137 assert.ok( jQuery.hasData( elem[ 0 ] ), "jQuery.hasData - true" );
141 if ( includesModule( "dimensions" ) ) {
142 QUnit.test( "dimensions", function( assert ) {
146 "<div style='margin: 10px; padding: 7px; border: 2px solid black;'></div> "
147 ).appendTo( "#qunit-fixture" );
149 assert.strictEqual( elem.width( 50 ).width(), 50, ".width getter/setter" );
150 assert.strictEqual( elem.innerWidth(), 64, ".innerWidth getter" );
151 assert.strictEqual( elem.outerWidth(), 68, ".outerWidth getter" );
155 if ( includesModule( "event" ) ) {
156 QUnit.test( "event", function( assert ) {
159 var elem = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" );
162 .on( "click", function() {
163 assert.ok( false, "click should not fire" );
167 .on( "click", function() {
168 assert.ok( true, "click should fire" );
174 if ( includesModule( "manipulation" ) ) {
175 QUnit.test( "manipulation", function( assert ) {
179 elem1 = jQuery( "<div><span></span></div>" ).appendTo( "#qunit-fixture" ),
180 elem2 = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" );
182 assert.strictEqual( elem1.text( "foo" ).text(), "foo", ".html getter/setter" );
185 elem1.html( "<span></span>" ).html(),
187 ".html getter/setter"
191 elem1.append( elem2 )[ 0 ].childNodes[ elem1[ 0 ].childNodes.length - 1 ],
195 assert.strictEqual( elem1.prepend( elem2 )[ 0 ].childNodes[ 0 ], elem2[ 0 ], ".prepend" );
197 child = elem1.find( "span" );
198 child.after( "<a></a>" );
199 child.before( "<b></b>" );
203 "<div></div><b></b><span></span><a></a>",
209 if ( includesModule( "offset" ) ) {
211 // Support: jsdom 13.2+
212 // jsdom returns 0 for offset-related properties
213 QUnit[ /jsdom\//.test( navigator.userAgent ) ? "skip" : "test" ]( "offset", function( assert ) {
216 var parent = jQuery( "<div style='position:fixed;top:20px;'></div>" ).appendTo( "#qunit-fixture" ),
217 elem = jQuery( "<div style='position:absolute;top:5px;'></div>" ).appendTo( parent );
219 assert.strictEqual( elem.offset().top, 25, ".offset getter" );
220 assert.strictEqual( elem.position().top, 5, ".position getter" );
221 assert.strictEqual( elem.offsetParent()[ 0 ], parent[ 0 ], ".offsetParent" );
225 QUnit.test( "selector", function( assert ) {
228 var elem = jQuery( "<div><span class='a'></span><span class='b'><a></a></span></div>" )
229 .appendTo( "#qunit-fixture" );
231 assert.strictEqual( elem.find( ".a a" ).length, 0, ".find - no result" );
232 assert.strictEqual( elem.find( "span.b a" )[ 0 ].nodeName, "A", ".find - one result" );
235 if ( includesModule( "serialize" ) ) {
236 QUnit.test( "serialize", function( assert ) {
239 var params = { "someName": [ 1, 2, 3 ], "regularThing": "blah" };
240 assert.strictEqual( jQuery.param( params ),
241 "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3®ularThing=blah",
244 assert.strictEqual( jQuery( "#form" ).serialize(),
245 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search" +
246 "&select1=&select2=3&select3=1&select3=2&select5=3",
247 "form serialization as query string" );
251 QUnit.test( "traversing", function( assert ) {
254 var elem = jQuery( "<div><a><b><em></em></b></a><i></i><span></span>foo</div>" )
255 .appendTo( "#qunit-fixture" );
257 assert.strictEqual( elem.find( "em" ).parent()[ 0 ].nodeName, "B", ".parent" );
258 assert.strictEqual( elem.find( "em" ).parents()[ 1 ].nodeName, "A", ".parents" );
259 assert.strictEqual( elem.find( "em" ).parentsUntil( "div" ).length, 2, ".parentsUntil" );
260 assert.strictEqual( elem.find( "i" ).next()[ 0 ].nodeName, "SPAN", ".next" );
261 assert.strictEqual( elem.find( "i" ).prev()[ 0 ].nodeName, "A", ".prev" );
262 assert.strictEqual( elem.find( "a" ).nextAll()[ 1 ].nodeName, "SPAN", ".nextAll" );
263 assert.strictEqual( elem.find( "span" ).prevAll()[ 1 ].nodeName, "A", ".prevAll" );
264 assert.strictEqual( elem.find( "a" ).nextUntil( "span" ).length, 1, ".nextUntil" );
265 assert.strictEqual( elem.find( "span" ).prevUntil( "a" ).length, 1, ".prevUntil" );
266 assert.strictEqual( elem.find( "i" ).siblings().length, 2, ".siblings" );
267 assert.strictEqual( elem.children()[ 2 ].nodeName, "SPAN", ".children" );
268 assert.strictEqual( elem.contents()[ 3 ].nodeType, 3, ".contents" );
271 if ( includesModule( "wrap" ) ) {
272 QUnit.test( "wrap", function( assert ) {
275 var elem = jQuery( "<div><a><b></b></a><a></a></div>" );
277 elem.find( "b" ).wrap( "<span>" );
281 "<a><span><b></b></span></a><a></a>",
285 elem.find( "span" ).wrapInner( "<em>" );
289 "<a><span><em><b></b></em></span></a><a></a>",
293 elem.find( "a" ).wrapAll( "<i>" );
297 "<i><a><span><em><b></b></em></span></a><a></a></i>",