Skip to content

Commit c7d458f

Browse files
committed
Tests: Backport basic tests from master
Commit 2c7e9c9 added the basic test suite; these are the only tests that are now run on Android 2.3 on master. On compat we're keeping full Android 2.3 support for now but the tests and the testswarm basic run mode have been cherry-picked anyway to reduce the divergence between branches. (cherry-picked from 2c7e9c9) Fixes gh-2505 Closes gh-2509 Refs gh-2483
1 parent 5f1c7fc commit c7d458f

File tree

4 files changed

+286
-4
lines changed

4 files changed

+286
-4
lines changed

Gruntfile.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,21 @@ module.exports = function( grunt ) {
126126
test: [
127127
"test/data/testrunner.js",
128128
"test/unit/animation.js",
129+
"test/unit/basic.js",
129130
"test/unit/tween.js",
130131
"test/unit/wrap.js"
131132
],
132133
build: "build"
133134
},
134135
testswarm: {
135136
tests: [
137+
138+
// A special module with basic tests, meant for
139+
// not fully supported environments like Android 2.3,
140+
// jsdom or PhantomJS. We run it everywhere, though,
141+
// to make sure tests are not broken.
142+
"basic",
143+
136144
"ajax",
137145
"animation",
138146
"attributes",

build/tasks/testswarm.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = function( grunt ) {
33
"use strict";
44

55
grunt.registerTask( "testswarm", function( commit, configFile, projectName, browserSets,
6-
timeout ) {
6+
timeout, testMode ) {
77
var jobName, config, tests,
88
testswarm = require( "testswarm" ),
99
runs = {},
@@ -29,9 +29,13 @@ module.exports = function( grunt ) {
2929
commit + "'>" + commit.substr( 0, 10 ) + "</a>";
3030
}
3131

32-
tests.forEach( function( test ) {
33-
runs[ test ] = config.testUrl + commit + "/test/index.html?module=" + test;
34-
} );
32+
if ( testMode === "basic" ) {
33+
runs.basic = config.testUrl + commit + "/test/index.html?module=basic";
34+
} else {
35+
tests.forEach( function( test ) {
36+
runs[ test ] = config.testUrl + commit + "/test/index.html?module=" + test;
37+
} );
38+
}
3539

3640
testswarm.createClient( {
3741
url: config.swarmUrl

test/data/testinit.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ this.loadTests = function() {
278278
// Get testSubproject from testrunner first
279279
require( [ "data/testrunner.js" ], function() {
280280
var tests = [
281+
// A special module with basic tests, meant for
282+
// not fully supported environments like Android 2.3,
283+
// jsdom or PhantomJS. We run it everywhere, though,
284+
// to make sure tests are not broken.
285+
"unit/basic.js",
286+
281287
"unit/core.js",
282288
"unit/callbacks.js",
283289
"unit/deferred.js",

test/unit/basic.js

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
QUnit.module( "basic", { teardown: moduleTeardown } );
2+
3+
if ( jQuery.ajax ) {
4+
QUnit.test( "ajax", function( assert ) {
5+
assert.expect( 4 );
6+
7+
var done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );
8+
9+
jQuery.ajax( {
10+
type: "GET",
11+
url: url( "data/name.php?name=foo" ),
12+
success: function( msg ) {
13+
assert.strictEqual( msg, "bar", "Check for GET" );
14+
done.pop()();
15+
}
16+
} );
17+
18+
jQuery.ajax( {
19+
type: "POST",
20+
url: url( "data/name.php" ),
21+
data: "name=peter",
22+
success: function( msg ) {
23+
assert.strictEqual( msg, "pan", "Check for POST" );
24+
done.pop()();
25+
}
26+
} );
27+
28+
jQuery( "#first" ).load( url( "data/name.html" ), function() {
29+
assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ),
30+
"Check if content was injected into the DOM" );
31+
done.pop()();
32+
} );
33+
} );
34+
}
35+
36+
QUnit.test( "attributes", function( assert ) {
37+
assert.expect( 6 );
38+
39+
var a = jQuery( "<a/>" ).appendTo( "#qunit-fixture" ),
40+
input = jQuery( "<input/>" ).appendTo( "#qunit-fixture" );
41+
42+
assert.strictEqual( a.attr( "foo", "bar" ).attr( "foo" ), "bar", ".attr getter/setter" );
43+
assert.strictEqual( a.removeAttr( "foo" ).attr( "foo" ), undefined, ".removeAttr" );
44+
assert.strictEqual( a.prop( "href", "#5" ).prop( "href" ),
45+
location.href.replace( /\#.*$/, "" ) + "#5",
46+
".prop getter/setter" );
47+
48+
a.addClass( "abc def ghj" ).removeClass( "def ghj" );
49+
assert.strictEqual( a.hasClass( "abc" ), true, ".(add|remove|has)Class, class present" );
50+
assert.strictEqual( a.hasClass( "def" ), false, ".(add|remove|has)Class, class missing" );
51+
52+
assert.strictEqual( input.val( "xyz" ).val(), "xyz", ".val getter/setter" );
53+
} );
54+
55+
if ( jQuery.css ) {
56+
QUnit.test( "css", function( assert ) {
57+
assert.expect( 3 );
58+
59+
var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
60+
61+
assert.strictEqual( div.css( "width", "50px" ).css( "width" ), "50px", ".css getter/setter" );
62+
63+
div.hide();
64+
assert.strictEqual( div.css( "display" ), "none", "div hidden" );
65+
div.show();
66+
assert.strictEqual( div.css( "display" ), "block", "div shown" );
67+
} );
68+
}
69+
70+
QUnit.test( "core", function( assert ) {
71+
assert.expect( 28 );
72+
73+
var elem = jQuery( "<div></div><span></span>" );
74+
75+
assert.strictEqual( elem.length, 2, "Correct number of elements" );
76+
assert.strictEqual( jQuery.trim( " hello " ), "hello", "jQuery.trim" );
77+
78+
assert.strictEqual( jQuery.type( null ), "null", "jQuery.type(null)" );
79+
assert.strictEqual( jQuery.type( undefined ), "undefined", "jQuery.type(undefined)" );
80+
assert.strictEqual( jQuery.type( "a" ), "string", "jQuery.type(String)" );
81+
82+
assert.ok( jQuery.isPlainObject( { "a": 2 } ), "jQuery.isPlainObject(object)" );
83+
assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" );
84+
85+
assert.ok( jQuery.isFunction( jQuery.noop ), "jQuery.isFunction(jQuery.noop)" );
86+
assert.ok( !jQuery.isFunction( 2 ), "jQuery.isFunction(Number)" );
87+
88+
assert.ok( jQuery.isNumeric( "-2" ), "jQuery.isNumeric(String representing a number)" );
89+
assert.ok( !jQuery.isNumeric( "" ), "jQuery.isNumeric(\"\")" );
90+
91+
assert.ok( jQuery.isXMLDoc( jQuery.parseXML(
92+
"<?xml version='1.0' encoding='UTF-8'?><foo bar='baz'></foo>"
93+
) ), "jQuery.isXMLDoc" );
94+
95+
assert.ok( jQuery.isWindow( window ), "jQuery.isWindow(window)" );
96+
assert.ok( !jQuery.isWindow( 2 ), "jQuery.isWindow(Number)" );
97+
98+
assert.strictEqual( jQuery.inArray( 3, [ "a", 6, false, 3, {} ] ), 3, "jQuery.inArray - true" );
99+
assert.strictEqual(
100+
jQuery.inArray( 3, [ "a", 6, false, "3", {} ] ),
101+
-1,
102+
"jQuery.inArray - false"
103+
);
104+
105+
assert.strictEqual( elem.get( 1 ), elem[ 1 ], ".get" );
106+
assert.strictEqual( elem.first()[ 0 ], elem[ 0 ], ".first" );
107+
assert.strictEqual( elem.last()[ 0 ], elem[ 1 ], ".last" );
108+
109+
assert.deepEqual( jQuery.map( [ "a", "b", "c" ], function( v, k ) {
110+
return k + v;
111+
} ), [ "0a", "1b", "2c" ], "jQuery.map" );
112+
113+
assert.deepEqual( jQuery.merge( [ 1, 2 ], [ "a", "b" ] ), [ 1, 2, "a", "b" ], "jQuery.merge" );
114+
115+
assert.deepEqual( jQuery.grep( [ 1, 2, 3 ], function( value ) {
116+
return value % 2 !== 0;
117+
} ), [ 1, 3 ], "jQuery.grep" );
118+
119+
assert.deepEqual( jQuery.extend( { a: 2 }, { b: 3 } ), { a: 2, b: 3 }, "jQuery.extend" );
120+
121+
jQuery.each( [ 0, 2 ], function( k, v ) {
122+
assert.strictEqual( k * 2, v, "jQuery.each" );
123+
} );
124+
125+
assert.deepEqual( jQuery.makeArray( { 0: "a", 1: "b", 2: "c", length: 3 } ),
126+
[ "a", "b", "c" ], "jQuery.makeArray" );
127+
128+
assert.strictEqual( jQuery.parseHTML( "<div></div><span></span>" ).length,
129+
2, "jQuery.parseHTML" );
130+
131+
assert.deepEqual( jQuery.parseJSON( "{\"a\": 2}" ), { a: 2 }, "jQuery.parseJON" );
132+
} );
133+
134+
QUnit.test( "data", function( assert ) {
135+
assert.expect( 4 );
136+
137+
var elem = jQuery( "<div data-c='d'/>" ).appendTo( "#qunit-fixture" );
138+
139+
assert.ok( !jQuery.hasData( elem[ 0 ] ), "jQuery.hasData - false" );
140+
assert.strictEqual( elem.data( "a", "b" ).data( "a" ), "b", ".data getter/setter" );
141+
assert.strictEqual( elem.data( "c" ), "d", ".data from data-* attributes" );
142+
assert.ok( jQuery.hasData( elem[ 0 ] ), "jQuery.hasData - true" );
143+
} );
144+
145+
QUnit.test( "dimensions", function( assert ) {
146+
assert.expect( 3 );
147+
148+
var elem = jQuery(
149+
"<div style='margin: 10px; padding: 7px; border: 2px solid black;' /> "
150+
).appendTo( "#qunit-fixture" );
151+
152+
assert.strictEqual( elem.width( 50 ).width(), 50, ".width getter/setter" );
153+
assert.strictEqual( elem.innerWidth(), 64, ".innerWidth getter" );
154+
assert.strictEqual( elem.outerWidth(), 68, ".outerWidth getter" );
155+
} );
156+
157+
QUnit.test( "event", function( assert ) {
158+
assert.expect( 1 );
159+
160+
var elem = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
161+
162+
elem
163+
.on( "click", function() {
164+
assert.ok( false, "click should not fire" );
165+
} )
166+
.off( "click" )
167+
.trigger( "click" )
168+
.on( "click", function() {
169+
assert.ok( true, "click should fire" );
170+
} )
171+
.trigger( "click" );
172+
} );
173+
174+
QUnit.test( "manipulation", function( assert ) {
175+
assert.expect( 5 );
176+
177+
var child,
178+
elem1 = jQuery( "<div><span></span></div>" ).appendTo( "#qunit-fixture" ),
179+
elem2 = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
180+
181+
assert.strictEqual( elem1.text( "foo" ).text(), "foo", ".html getter/setter" );
182+
assert.strictEqual( elem1.html( "<span/>" ).html(), "<span></span>", ".html getter/setter" );
183+
184+
assert.strictEqual( elem1.append( elem2 )[ 0 ].childNodes[ 1 ], elem2[ 0 ], ".append" );
185+
assert.strictEqual( elem1.prepend( elem2 )[ 0 ].childNodes[ 0 ], elem2[ 0 ], ".prepend" );
186+
187+
child = elem1.find( "span" );
188+
child.after( "<a/>" );
189+
child.before( "<b/>" );
190+
assert.strictEqual( elem1.html(), "<div></div><b></b><span></span><a></a>", ".after/.before" );
191+
} );
192+
193+
QUnit.test( "offset", function( assert ) {
194+
assert.expect( 3 );
195+
196+
var parent = jQuery( "<div style='position:fixed;top:20px;'/>" ).appendTo( "#qunit-fixture" ),
197+
elem = jQuery( "<div style='position:absolute;top:5px;'/>" ).appendTo( parent );
198+
199+
assert.strictEqual( elem.offset().top, 25, ".offset getter" );
200+
assert.strictEqual( elem.position().top, 5, ".position getter" );
201+
assert.strictEqual( elem.offsetParent()[ 0 ], parent[ 0 ], ".offsetParent" );
202+
} );
203+
204+
QUnit.test( "selector", function( assert ) {
205+
assert.expect( 2 );
206+
207+
var elem = jQuery( "<div><span class='a'></span><span class='b'><a></a></span></div>" )
208+
.appendTo( "#qunit-fixture" );
209+
210+
assert.strictEqual( elem.find( ".a a" ).length, 0, ".find - no result" );
211+
assert.strictEqual( elem.find( "span.b a" )[ 0 ].nodeName, "A", ".find - one result" );
212+
} );
213+
214+
QUnit.test( "serialize", function( assert ) {
215+
assert.expect( 2 );
216+
217+
var params = { "someName": [ 1, 2, 3 ], "regularThing": "blah" };
218+
assert.strictEqual( jQuery.param( params ),
219+
"someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah",
220+
"jQuery.param" );
221+
222+
assert.strictEqual( jQuery( "#form" ).serialize(),
223+
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search" +
224+
"&select1=&select2=3&select3=1&select3=2&select5=3",
225+
"form serialization as query string" );
226+
} );
227+
228+
QUnit.test( "traversing", function( assert ) {
229+
assert.expect( 12 );
230+
231+
var elem = jQuery( "<div><a><b><em></em></b></a><i></i><span></span>foo</div>" )
232+
.appendTo( "#qunit-fixture" );
233+
234+
assert.strictEqual( elem.find( "em" ).parent()[ 0 ].nodeName, "B", ".parent" );
235+
assert.strictEqual( elem.find( "em" ).parents()[ 1 ].nodeName, "A", ".parents" );
236+
assert.strictEqual( elem.find( "em" ).parentsUntil( "div" ).length, 2, ".parentsUntil" );
237+
assert.strictEqual( elem.find( "i" ).next()[ 0 ].nodeName, "SPAN", ".next" );
238+
assert.strictEqual( elem.find( "i" ).prev()[ 0 ].nodeName, "A", ".prev" );
239+
assert.strictEqual( elem.find( "a" ).nextAll()[ 1 ].nodeName, "SPAN", ".nextAll" );
240+
assert.strictEqual( elem.find( "span" ).prevAll()[ 1 ].nodeName, "A", ".prevAll" );
241+
assert.strictEqual( elem.find( "a" ).nextUntil( "span" ).length, 1, ".nextUntil" );
242+
assert.strictEqual( elem.find( "span" ).prevUntil( "a" ).length, 1, ".prevUntil" );
243+
assert.strictEqual( elem.find( "i" ).siblings().length, 2, ".siblings" );
244+
assert.strictEqual( elem.children()[ 2 ].nodeName, "SPAN", ".children" );
245+
assert.strictEqual( elem.contents()[ 3 ].nodeType, 3, ".contents" );
246+
} );
247+
248+
QUnit.test( "wrap", function( assert ) {
249+
assert.expect( 3 );
250+
251+
var elem = jQuery( "<div><a><b></b></a><a></a></div>" );
252+
253+
elem.find( "b" ).wrap( "<span>" );
254+
assert.strictEqual( elem.html(), "<a><span><b></b></span></a><a></a>", ".wrap" );
255+
elem.find( "span" ).wrapInner( "<em>" );
256+
assert.strictEqual( elem.html(), "<a><span><em><b></b></em></span></a><a></a>", ".wrapInner" );
257+
elem.find( "a" ).wrapAll( "<i>" );
258+
assert.strictEqual(
259+
elem.html(),
260+
"<i><a><span><em><b></b></em></span></a><a></a></i>",
261+
".wrapAll"
262+
);
263+
264+
} );

0 commit comments

Comments
 (0)