-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyQuery-test.html
67 lines (60 loc) · 2.1 KB
/
yQuery-test.html
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
61
62
63
64
65
66
67
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css"/>
<link rel="stylesheet" href="../yQuery/lib/qunit.css"/>
<title>yQuery Test</title>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-area"></div>
<script src="yQuery.js"></script>
<script src="../yQuery/lib/qunit.js"></script>
<script>
module('yQuery utilities');
test('$.extend', function() {
var target = { first: 'Yan'},
obj = { last: 'Fan'};
var result = $.extend(target, obj);
equal(result, target, 'The target and the result should be equal');
deepEqual(result, {first: 'Yan', last: 'Fan'}, 'Properties should be correctly added');
});
test('$.isArray', function() {
var obj = {1: 'a', 'foo': 'b'};
var arr = [1,2,3,4,5];
var result = $.isArray(obj);
var result2 = $.isArray(arr);
equal(result, false, 'An object should not be an array');
equal(result2, true, 'An array should return true');
});
test('$.each', function() {
var obj = ['a','b'];
var result = $.each(obj, function(index, value){
if(index === 0 ) equal(value, 'a', 'how is it with an array?');
else if(index === 1 ) equal(value, 'b', 'can it find the index at 1?');
else ok(false,'you\'re on the wrong index, dude');
});
equal(obj, result);
obj = {name: 'yan', age: '25'};
result = $.each(obj, function(prop, value){
if(prop === 'name' ) equal(value, 'yan', 'can it work with objects?');
else if(prop === 'age' ) equal(value, '25', 'can it work with more objects?');
else ok(false, 'you\'re on the wrong index, dude');
});
equal(obj, result);
var obj = {0:'a', 1:'b', length: 2};
var result = $.each(obj, function(index, value){
if(index === 0 ) equal(value, 'a');
else if(index === 1 ) equal(value, 'b');
else ok(false, 'you\'re on the wrong index, dude');
});
equal(obj, result);
});
//takes in an
test('$.map', function() {
$('body').append('<li>hello</li>');
});
</script>
</body>
</html>