Skip to content

Commit 7a36083

Browse files
committed
[WIP]: Add simple tests for Android 2.3
Fixes gh-2505 Refs gh-2483
1 parent 669cb16 commit 7a36083

File tree

4 files changed

+176
-4
lines changed

4 files changed

+176
-4
lines changed

Gruntfile.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ module.exports = function( grunt ) {
114114
},
115115
testswarm: {
116116
tests: [
117+
// A special module with basic tests, meant for
118+
// not fully supported environments like Android 2.3,
119+
// jsdom or PhantomJS. We run it everywhere, though,
120+
// to make sure tests are not broken.
121+
"basic",
122+
117123
"ajax",
118124
"animation",
119125
"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 = {},
@@ -28,9 +28,13 @@ module.exports = function( grunt ) {
2828
commit + "'>" + commit.substr( 0, 10 ) + "</a>";
2929
}
3030

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

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

test/data/testinit.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ this.loadTests = function() {
268268
// Get testSubproject from testrunner first
269269
require([ "data/testrunner.js" ], function() {
270270
var tests = [
271+
// A special module with basic tests, meant for
272+
// not fully supported environments like Android 2.3,
273+
// jsdom or PhantomJS. We run it everywhere, though,
274+
// to make sure tests are not broken.
275+
"unit/basic.js",
276+
271277
"unit/core.js",
272278
"unit/callbacks.js",
273279
"unit/deferred.js",

test/unit/basic.js

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
module( "basic", {
2+
teardown: moduleTeardown
3+
} );
4+
5+
if ( jQuery.ajax ) {
6+
test( "ajax", function( assert ) {
7+
expect( 4 );
8+
9+
var requestsLeft = 3;
10+
11+
stop();
12+
13+
jQuery.ajax({
14+
type: "GET",
15+
url: url( "data/name.php?name=foo" ),
16+
success: function( msg ) {
17+
assert.strictEqual( msg, "bar", "Check for GET" );
18+
requestsLeft--;
19+
if ( !requestsLeft ) {
20+
start();
21+
}
22+
}
23+
});
24+
25+
jQuery.ajax({
26+
type: "POST",
27+
url: url( "data/name.php" ),
28+
data: "name=peter",
29+
success: function( msg ) {
30+
strictEqual( msg, "pan", "Check for POST" );
31+
requestsLeft--;
32+
if ( !requestsLeft ) {
33+
start();
34+
}
35+
}
36+
});
37+
38+
jQuery( "#first" ).load( url( "data/name.html" ), function() {
39+
assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ),
40+
"Check if content was injected into the DOM" );
41+
requestsLeft--;
42+
if ( !requestsLeft ) {
43+
start();
44+
}
45+
});
46+
} );
47+
}
48+
49+
test( "attributes", function ( assert ) {
50+
expect( 6 );
51+
52+
var a = jQuery( "<a/>" ).appendTo( "#qunit-fixture" ),
53+
input = jQuery( "<input/>" ).appendTo( "#qunit-fixture" );
54+
55+
assert.strictEqual( a.attr( "foo", "bar" ).attr( "foo" ), "bar", ".attr getter/setter" );
56+
assert.strictEqual( a.removeAttr( "foo" ).attr( "foo" ), undefined, ".removeAttr" );
57+
assert.strictEqual( a.prop( "href", "#5" ).prop( "href" ),
58+
location.href.replace( /\#.*$/, "" ) + "#5",
59+
".prop getter/setter" );
60+
61+
a.addClass( "abc def ghj" ).removeClass( "def ghj" );
62+
assert.strictEqual( a.hasClass( "abc" ), true, ".(add|remove|has)Class, class present" );
63+
assert.strictEqual( a.hasClass( "def" ), false, ".(add|remove|has)Class, class missing" );
64+
65+
assert.strictEqual( input.val( "xyz" ).val(), "xyz", ".val getter/setter" );
66+
} );
67+
68+
if ( jQuery.css ) {
69+
test( "css", function( assert ) {
70+
expect( 3 );
71+
72+
var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
73+
74+
assert.strictEqual( div.css( "width", "50px" ).css( "width" ), "50px", ".css getter/setter" );
75+
76+
div.hide();
77+
assert.strictEqual( div.css( "display" ), "none", "div hidden" );
78+
div.show();
79+
assert.strictEqual( div.css( "display" ), "block", "div shown" );
80+
} );
81+
}
82+
83+
test( "core", function ( assert ) {
84+
expect( 28 );
85+
86+
var elem = jQuery( "<div></div><span></span>" );
87+
88+
assert.strictEqual( elem.length, 2, "Correct number of elements" );
89+
assert.strictEqual( jQuery.trim(" hello "), "hello", "jQuery.trim" );
90+
91+
assert.strictEqual( jQuery.type( null ), "null", "jQuery.type(null)" );
92+
assert.strictEqual( jQuery.type( undefined ), "undefined", "jQuery.type(undefined)" );
93+
assert.strictEqual( jQuery.type("a"), "string", "jQuery.type(String)" );
94+
95+
assert.ok( jQuery.isPlainObject({ "a": 2 }), "jQuery.isPlainObject(object)" );
96+
assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" );
97+
98+
assert.ok( jQuery.isFunction( jQuery.noop ), "jQuery.isFunction(jQuery.noop)" );
99+
assert.ok( !jQuery.isFunction( 2 ), "jQuery.isFunction(Number)" );
100+
101+
assert.ok( jQuery.isNumeric( "-2" ), "jQuery.isNumeric(String representing a number)" );
102+
assert.ok( !jQuery.isNumeric( "" ), "jQuery.isNumeric(\"\")" );
103+
104+
assert.ok( jQuery.isXMLDoc( jQuery.parseXML(
105+
"<?xml version='1.0' encoding='UTF-8'?><foo bar='baz'></foo>"
106+
) ), "jQuery.isXMLDoc" );
107+
108+
109+
assert.ok( jQuery.isWindow( window ), "jQuery.isWindow(window)" );
110+
assert.ok( !jQuery.isWindow( 2 ), "jQuery.isWindow(Number)" );
111+
112+
assert.strictEqual( jQuery.inArray( 3, [ "a", 6, false, 3, {} ] ), 3, "jQuery.inArray - true" );
113+
assert.strictEqual( jQuery.inArray( 3, [ "a", 6, false, "3", {} ] ), -1, "jQuery.inArray - false" );
114+
115+
assert.strictEqual( elem.get( 1 ), elem[ 1 ], ".get" );
116+
assert.strictEqual( elem.first()[ 0 ], elem.get( 0 ), ".first" );
117+
assert.strictEqual( elem.last()[ 0 ], elem.get( 1 ), ".last" );
118+
119+
assert.deepEqual( jQuery.map( [ "a", "b", "c" ], function ( v, k ) {
120+
return k + v;
121+
} ), ["0a", "1b", "2c" ], "jQuery.map" );
122+
123+
assert.deepEqual( jQuery.merge( [ 1, 2 ], [ "a", "b" ] ), [ 1, 2, "a", "b" ], "jQuery.merge" );
124+
125+
assert.deepEqual( jQuery.grep( [ 1, 2, 3 ], function( value ) {
126+
return value % 2 !== 0;
127+
} ), [ 1, 3 ], "jQuery.grep" );
128+
129+
assert.deepEqual( jQuery.extend( { a: 2 }, { b: 3 } ), { a: 2, b: 3 }, "jQuery.extend" );
130+
131+
jQuery.each( [ 0, 2 ], function ( k, v ) {
132+
assert.strictEqual( k * 2, v, "jQuery.each" );
133+
} );
134+
135+
assert.deepEqual( jQuery.makeArray( { 0: "a", 1: "b", 2: "c", length: 3 } ),
136+
[ "a", "b", "c" ], "jQuery.makeArray" );
137+
138+
assert.strictEqual( jQuery.parseHTML( "<div></div><span></span>" ).length,
139+
2, "jQuery.parseHTML" );
140+
141+
assert.deepEqual( jQuery.parseJSON( "{\"a\": 2}" ), { a: 2 }, "jQuery.parseJON" );
142+
} );
143+
144+
test( "data", function ( assert ) {
145+
expect( 4 );
146+
147+
var elem = jQuery( "<div data-c='d'/>" ).appendTo( "#qunit-fixture" );
148+
149+
assert.ok( !jQuery.hasData( elem[ 0 ] ), "jQuery.hasData - false" );
150+
assert.strictEqual( elem.data( "a", "b" ).data( "a" ), "b", ".data getter/setter" );
151+
assert.strictEqual( elem.data( "c" ), "d", ".data from data-* attributes" );
152+
assert.ok( jQuery.hasData( elem[ 0 ] ), "jQuery.hasData - true" );
153+
} );
154+
155+
// TODO write tests for deferred, dimensions, effects, event, manipulation, offset,
156+
// ready, selector, serialize, traversing & wrap.

0 commit comments

Comments
 (0)