-
Notifications
You must be signed in to change notification settings - Fork 28
/
test.html
101 lines (75 loc) · 2.34 KB
/
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script>
var frag = document.createDocumentFragment();
window.it = function(msg, callback) {
var div = document.createElement('div');
div.textContent = msg;
frag.appendChild(div);
callback(function() {
div.style.color = 'green';
}, function() {
div.style.color = 'red';
});
}
window.onload = function() {
document.body.appendChild(frag);
};
</script>
<script src="tsimmes.min.js"></script>
<script src="https://cdn.jsdelivr.net/requirejs/2.1.22/require.min.js"></script>
</head>
<body>
<div class="test">
<div class="test-1"></div>
</div>
<script>
it('Converts array-like', function(ok, fail) {
var all = document.querySelectorAll('*'),
$all = $(all);
$all.length == all.length && all[0] == $all[0] ? ok() : fail();
});
it('Converts one element', function(ok, fail) {
var element = document.querySelector('*'),
$element = $(element);
$element[0] == element && $element.length == 1 ? ok() : fail();
});
it('Uses context', function(ok, fail) {
$('.test-1', '.test').length && !$('.test-xx', '.test').length ? ok() : fail();
});
it('Doesn\'t use wrong context', function(ok, fail) {
!$('.test', '.test-undefined').length ? ok() : fail();
});
it('Allows to use window', function(ok, fail) {
$(window)[0] === window ? ok() : fail();
});
it('Allows to use undefined and null', function(ok, fail) {
!$(null).length && !$().length ? ok() : fail();
});
it('Allows to use document', function(ok, fail) {
$(document)[0] === document ? ok() : fail();
});
it('Parses HTML', function(ok, fail) {
var $el = $('<div></div><span></span>');
$el.length == 2 && $el[0].tagName == 'DIV' && $el[1].tagName == 'SPAN' ? ok() : fail();
});
it('Parses contextual HTML', function(ok, fail) {
var $el = $('<td></td><td></td>', 'tr');
$el.length == 2 && $el[0].tagName == 'TD' && $el[1].tagName == 'TD' ? ok() : fail();
});
it('Little test for $.one', function(ok, fail) {
$.one('.test').className == 'test' ? ok() : fail();
});
it('Works with AMD', function(ok, fail) {
var timeout = setTimeout(fail, 1000);
require(['./bala.umd.js'], function($) {
if($.one('.test').className == 'test') {
ok();
clearTimeout(timeout);
}
});
});
</script>
</body>
</html>