1
1
describe ( 'jqLite' , function ( ) {
2
- var scope ;
3
- var a , b , c ;
2
+ var scope , a , b , c ;
3
+
4
4
beforeEach ( function ( ) {
5
5
a = jqLite ( '<div>A</div>' ) [ 0 ] ;
6
6
b = jqLite ( '<div>B</div>' ) [ 0 ] ;
7
7
c = jqLite ( '<div>C</div>' ) [ 0 ] ;
8
8
} ) ;
9
9
10
+
10
11
beforeEach ( function ( ) {
11
12
scope = angular . scope ( ) ;
12
13
this . addMatchers ( {
@@ -28,12 +29,14 @@ describe('jqLite', function(){
28
29
} ) ;
29
30
} ) ;
30
31
32
+
31
33
afterEach ( function ( ) {
32
34
dealoc ( a ) ;
33
35
dealoc ( b ) ;
34
36
dealoc ( c ) ;
35
37
} ) ;
36
38
39
+
37
40
describe ( 'construction' , function ( ) {
38
41
it ( 'should allow construction with text node' , function ( ) {
39
42
var text = a . firstChild ;
@@ -42,32 +45,37 @@ describe('jqLite', function(){
42
45
expect ( selected [ 0 ] ) . toEqual ( text ) ;
43
46
} ) ;
44
47
48
+
45
49
it ( 'should allow construction with html' , function ( ) {
46
50
var nodes = jqLite ( '<div>1</div><span>2</span>' ) ;
47
51
expect ( nodes . length ) . toEqual ( 2 ) ;
48
52
expect ( nodes [ 0 ] . innerHTML ) . toEqual ( '1' ) ;
49
53
expect ( nodes [ 1 ] . innerHTML ) . toEqual ( '2' ) ;
50
54
} ) ;
51
55
56
+
52
57
it ( 'should allow creation of comment tags' , function ( ) {
53
58
var nodes = jqLite ( '<!-- foo -->' ) ;
54
59
expect ( nodes . length ) . toBe ( 1 ) ;
55
60
expect ( nodes [ 0 ] . nodeType ) . toBe ( 8 ) ;
56
61
} ) ;
57
62
63
+
58
64
it ( 'should allow creation of script tags' , function ( ) {
59
65
var nodes = jqLite ( '<script></script>' ) ;
60
66
expect ( nodes . length ) . toBe ( 1 ) ;
61
67
expect ( nodes [ 0 ] . tagName . toUpperCase ( ) ) . toBe ( 'SCRIPT' ) ;
62
68
} ) ;
63
69
70
+
64
71
it ( 'should wrap document fragment' , function ( ) {
65
72
var fragment = jqLite ( document . createDocumentFragment ( ) ) ;
66
73
expect ( fragment . length ) . toBe ( 1 ) ;
67
74
expect ( fragment [ 0 ] . nodeType ) . toBe ( 11 ) ;
68
75
} ) ;
69
76
} ) ;
70
77
78
+
71
79
describe ( 'scope' , function ( ) {
72
80
it ( 'should retrieve scope attached to the current element' , function ( ) {
73
81
var element = jqLite ( '<i>foo</i>' ) ;
@@ -76,6 +84,7 @@ describe('jqLite', function(){
76
84
dealoc ( element ) ;
77
85
} ) ;
78
86
87
+
79
88
it ( 'should walk up the dom to find scope' , function ( ) {
80
89
var element = jqLite ( '<ul><li><p><b>deep deep</b><p></li></ul>' ) ;
81
90
var deepChild = jqLite ( element [ 0 ] . getElementsByTagName ( 'b' ) [ 0 ] ) ;
@@ -84,6 +93,7 @@ describe('jqLite', function(){
84
93
dealoc ( element ) ;
85
94
} ) ;
86
95
96
+
87
97
it ( 'should return undefined when no scope was found' , function ( ) {
88
98
var element = jqLite ( '<ul><li><p><b>deep deep</b><p></li></ul>' ) ;
89
99
var deepChild = jqLite ( element [ 0 ] . getElementsByTagName ( 'b' ) [ 0 ] ) ;
@@ -92,6 +102,7 @@ describe('jqLite', function(){
92
102
} ) ;
93
103
} ) ;
94
104
105
+
95
106
describe ( 'data' , function ( ) {
96
107
it ( 'should set and get ande remove data' , function ( ) {
97
108
var selected = jqLite ( [ a , b , c ] ) ;
@@ -115,6 +126,7 @@ describe('jqLite', function(){
115
126
} ) ;
116
127
} ) ;
117
128
129
+
118
130
describe ( 'attr' , function ( ) {
119
131
it ( 'shoul read wirite and remove attr' , function ( ) {
120
132
var selector = jqLite ( [ a , b ] ) ;
@@ -136,13 +148,18 @@ describe('jqLite', function(){
136
148
expect ( jqLite ( b ) . attr ( 'prop' ) ) . toBeFalsy ( ) ;
137
149
} ) ;
138
150
} ) ;
151
+
152
+
139
153
describe ( 'class' , function ( ) {
154
+
140
155
describe ( 'hasClass' , function ( ) {
141
156
it ( 'should check class' , function ( ) {
142
157
var selector = jqLite ( [ a , b ] ) ;
143
158
expect ( selector . hasClass ( 'abc' ) ) . toEqual ( false ) ;
144
159
} ) ;
145
160
} ) ;
161
+
162
+
146
163
describe ( 'addClass' , function ( ) {
147
164
it ( 'should allow adding of class' , function ( ) {
148
165
var selector = jqLite ( [ a , b ] ) ;
@@ -151,6 +168,8 @@ describe('jqLite', function(){
151
168
expect ( jqLite ( b ) . hasClass ( 'abc' ) ) . toEqual ( true ) ;
152
169
} ) ;
153
170
} ) ;
171
+
172
+
154
173
describe ( 'toggleClass' , function ( ) {
155
174
it ( 'should allow toggling of class' , function ( ) {
156
175
var selector = jqLite ( [ a , b ] ) ;
@@ -172,6 +191,8 @@ describe('jqLite', function(){
172
191
173
192
} ) ;
174
193
} ) ;
194
+
195
+
175
196
describe ( 'removeClass' , function ( ) {
176
197
it ( 'should allow removal of class' , function ( ) {
177
198
var selector = jqLite ( [ a , b ] ) ;
@@ -182,6 +203,8 @@ describe('jqLite', function(){
182
203
} ) ;
183
204
} ) ;
184
205
} ) ;
206
+
207
+
185
208
describe ( 'css' , function ( ) {
186
209
it ( 'should set and read css' , function ( ) {
187
210
var selector = jqLite ( [ a , b ] ) ;
@@ -203,12 +226,15 @@ describe('jqLite', function(){
203
226
expect ( jqLite ( b ) . css ( 'prop' ) ) . toBeFalsy ( ) ;
204
227
} ) ;
205
228
} ) ;
229
+
230
+
206
231
describe ( 'text' , function ( ) {
207
232
it ( 'should return null on empty' , function ( ) {
208
233
expect ( jqLite ( ) . length ) . toEqual ( 0 ) ;
209
234
expect ( jqLite ( ) . text ( ) ) . toEqual ( '' ) ;
210
235
} ) ;
211
236
237
+
212
238
it ( 'should read/write value' , function ( ) {
213
239
var element = jqLite ( '<div>abc</div>' ) ;
214
240
expect ( element . length ) . toEqual ( 1 ) ;
@@ -218,6 +244,8 @@ describe('jqLite', function(){
218
244
expect ( element . text ( ) ) . toEqual ( 'xyz' ) ;
219
245
} ) ;
220
246
} ) ;
247
+
248
+
221
249
describe ( 'val' , function ( ) {
222
250
it ( 'should read, write value' , function ( ) {
223
251
var input = jqLite ( '<input type="text"/>' ) ;
@@ -226,12 +254,15 @@ describe('jqLite', function(){
226
254
expect ( input . val ( ) ) . toEqual ( 'abc' ) ;
227
255
} ) ;
228
256
} ) ;
257
+
258
+
229
259
describe ( 'html' , function ( ) {
230
260
it ( 'should return null on empty' , function ( ) {
231
261
expect ( jqLite ( ) . length ) . toEqual ( 0 ) ;
232
262
expect ( jqLite ( ) . html ( ) ) . toEqual ( null ) ;
233
263
} ) ;
234
264
265
+
235
266
it ( 'should read/write value' , function ( ) {
236
267
var element = jqLite ( '<div>abc</div>' ) ;
237
268
expect ( element . length ) . toEqual ( 1 ) ;
@@ -242,6 +273,7 @@ describe('jqLite', function(){
242
273
} ) ;
243
274
} ) ;
244
275
276
+
245
277
describe ( 'bind' , function ( ) {
246
278
it ( 'should bind to window on hashchange' , function ( ) {
247
279
if ( jqLite . fn ) return ; // don't run in jQuery
@@ -272,6 +304,7 @@ describe('jqLite', function(){
272
304
dealoc ( jWindow ) ;
273
305
} ) ;
274
306
307
+
275
308
it ( 'should bind to all elements and return functions' , function ( ) {
276
309
var selected = jqLite ( [ a , b ] ) ;
277
310
var log = '' ;
@@ -285,20 +318,25 @@ describe('jqLite', function(){
285
318
} ) ;
286
319
} ) ;
287
320
321
+
288
322
describe ( 'replaceWith' , function ( ) {
289
323
it ( 'should replaceWith' , function ( ) {
290
324
var root = jqLite ( '<div>' ) . html ( 'before-<div></div>after' ) ;
291
325
var div = root . find ( 'div' ) ;
292
326
expect ( div . replaceWith ( '<span>span-</span><b>bold-</b>' ) ) . toEqual ( div ) ;
293
327
expect ( root . text ( ) ) . toEqual ( 'before-span-bold-after' ) ;
294
328
} ) ;
329
+
330
+
295
331
it ( 'should replaceWith text' , function ( ) {
296
332
var root = jqLite ( '<div>' ) . html ( 'before-<div></div>after' ) ;
297
333
var div = root . find ( 'div' ) ;
298
334
expect ( div . replaceWith ( 'text-' ) ) . toEqual ( div ) ;
299
335
expect ( root . text ( ) ) . toEqual ( 'before-text-after' ) ;
300
336
} ) ;
301
337
} ) ;
338
+
339
+
302
340
describe ( 'children' , function ( ) {
303
341
it ( 'should select non-text children' , function ( ) {
304
342
var root = jqLite ( '<div>' ) . html ( 'before-<div></div>after-<span></span>' ) ;
@@ -307,6 +345,8 @@ describe('jqLite', function(){
307
345
expect ( root . children ( ) ) . toJqEqual ( [ div , span ] ) ;
308
346
} ) ;
309
347
} ) ;
348
+
349
+
310
350
describe ( 'append' , function ( ) {
311
351
it ( 'should append' , function ( ) {
312
352
var root = jqLite ( '<div>' ) ;
@@ -324,6 +364,8 @@ describe('jqLite', function(){
324
364
expect ( root . children ( ) . length ) . toBe ( 0 ) ;
325
365
} ) ;
326
366
} ) ;
367
+
368
+
327
369
describe ( 'remove' , function ( ) {
328
370
it ( 'should remove' , function ( ) {
329
371
var root = jqLite ( '<div><span>abc</span></div>' ) ;
@@ -332,20 +374,26 @@ describe('jqLite', function(){
332
374
expect ( root . html ( ) ) . toEqual ( '' ) ;
333
375
} ) ;
334
376
} ) ;
377
+
378
+
335
379
describe ( 'after' , function ( ) {
336
380
it ( 'should after' , function ( ) {
337
381
var root = jqLite ( '<div><span></span></div>' ) ;
338
382
var span = root . find ( 'span' ) ;
339
383
expect ( span . after ( '<i></i><b></b>' ) ) . toEqual ( span ) ;
340
384
expect ( root . html ( ) . toLowerCase ( ) ) . toEqual ( '<span></span><i></i><b></b>' ) ;
341
385
} ) ;
386
+
387
+
342
388
it ( 'should allow taking text' , function ( ) {
343
389
var root = jqLite ( '<div><span></span></div>' ) ;
344
390
var span = root . find ( 'span' ) ;
345
391
span . after ( 'abc' ) ;
346
392
expect ( root . html ( ) . toLowerCase ( ) ) . toEqual ( '<span></span>abc' ) ;
347
393
} ) ;
348
394
} ) ;
395
+
396
+
349
397
describe ( 'parent' , function ( ) {
350
398
it ( 'should return parent or an empty set when no parent' , function ( ) {
351
399
var parent = jqLite ( '<div><p>abc</p></div>' ) ,
@@ -357,11 +405,15 @@ describe('jqLite', function(){
357
405
expect ( child . parent ( ) . length ) . toBe ( 1 ) ;
358
406
expect ( child . parent ( ) [ 0 ] ) . toBe ( parent [ 0 ] ) ;
359
407
} ) ;
408
+
409
+
360
410
it ( 'should return empty set when no parent' , function ( ) {
361
411
var element = jqLite ( '<div>abc</div>' ) ;
362
412
expect ( element . parent ( ) ) . toBeTruthy ( ) ;
363
413
expect ( element . parent ( ) . length ) . toEqual ( 0 ) ;
364
414
} ) ;
415
+
416
+
365
417
it ( 'should return empty jqLite object when parent is a document fragment' , function ( ) {
366
418
//this is quite unfortunate but jQuery 1.5.1 behaves this way
367
419
var fragment = document . createDocumentFragment ( ) ,
@@ -372,6 +424,8 @@ describe('jqLite', function(){
372
424
expect ( child . parent ( ) . length ) . toBe ( 0 ) ;
373
425
} ) ;
374
426
} ) ;
427
+
428
+
375
429
describe ( 'next' , function ( ) {
376
430
it ( 'should return next sibling' , function ( ) {
377
431
var element = jqLite ( '<div><b>b</b><i>i</i></div>' ) ;
@@ -380,6 +434,8 @@ describe('jqLite', function(){
380
434
expect ( b . next ( ) ) . toJqEqual ( [ i ] ) ;
381
435
} ) ;
382
436
} ) ;
437
+
438
+
383
439
describe ( 'find' , function ( ) {
384
440
it ( 'should find child by name' , function ( ) {
385
441
var root = jqLite ( '<div><div>text</div></div>' ) ;
@@ -388,5 +444,4 @@ describe('jqLite', function(){
388
444
expect ( innerDiv . html ( ) ) . toEqual ( 'text' ) ;
389
445
} ) ;
390
446
} ) ;
391
-
392
447
} ) ;
0 commit comments