1
1
'use strict' ;
2
2
3
3
describe ( 'widget' , function ( ) {
4
- describe ( 'ng:switch' , inject ( function ( $rootScope , $compile ) {
4
+ describe ( 'ng:switch' , function ( ) {
5
5
it ( 'should switch on value change' , inject ( function ( $rootScope , $compile ) {
6
6
var element = $compile (
7
7
'<ng:switch on="select">' +
@@ -26,7 +26,7 @@ describe('widget', function() {
26
26
$rootScope . $apply ( ) ;
27
27
expect ( element . text ( ) ) . toEqual ( 'true:misko' ) ;
28
28
} ) ) ;
29
-
29
+
30
30
31
31
it ( 'should switch on switch-when-default' , inject ( function ( $rootScope , $compile ) {
32
32
var element = $compile (
@@ -41,7 +41,7 @@ describe('widget', function() {
41
41
expect ( element . text ( ) ) . toEqual ( 'one' ) ;
42
42
} ) ) ;
43
43
44
-
44
+
45
45
it ( 'should call change on switch' , inject ( function ( $rootScope , $compile ) {
46
46
var element = $compile (
47
47
'<ng:switch on="url" change="name=\'works\'">' +
@@ -52,7 +52,7 @@ describe('widget', function() {
52
52
expect ( $rootScope . name ) . toEqual ( undefined ) ;
53
53
expect ( element . text ( ) ) . toEqual ( 'works' ) ;
54
54
} ) ) ;
55
- } ) ) ;
55
+ } ) ;
56
56
57
57
58
58
describe ( 'ng:include' , inject ( function ( $rootScope , $compile ) {
@@ -149,6 +149,7 @@ describe('widget', function() {
149
149
expect ( $rootScope . $$childHead ) . toBeFalsy ( ) ;
150
150
} ) ) ;
151
151
152
+
152
153
it ( 'should do xhr request and cache it' ,
153
154
inject ( function ( $rootScope , $httpBackend , $compile , $browser ) {
154
155
var element = $compile ( '<ng:include src="url"></ng:include>' ) ( $rootScope ) ;
@@ -170,6 +171,7 @@ describe('widget', function() {
170
171
dealoc ( $rootScope ) ;
171
172
} ) ) ;
172
173
174
+
173
175
it ( 'should clear content when error during xhr request' ,
174
176
inject ( function ( $httpBackend , $compile , $rootScope ) {
175
177
var element = $compile ( '<ng:include src="url">content</ng:include>' ) ( $rootScope ) ;
@@ -182,6 +184,7 @@ describe('widget', function() {
182
184
expect ( element . text ( ) ) . toBe ( '' ) ;
183
185
} ) ) ;
184
186
187
+
185
188
it ( 'should be async even if served from cache' , inject (
186
189
putIntoCache ( 'myUrl' , 'my partial' ) ,
187
190
function ( $rootScope , $compile , $browser ) {
@@ -200,6 +203,7 @@ describe('widget', function() {
200
203
expect ( element . text ( ) ) . toBe ( 'my partial' ) ;
201
204
} ) ) ;
202
205
206
+
203
207
it ( 'should discard pending xhr callbacks if a new template is requested before the current ' +
204
208
'finished loading' , inject ( function ( $rootScope , $compile , $httpBackend ) {
205
209
var element = jqLite ( "<ng:include src='templateUrl'></ng:include>" ) ,
@@ -226,7 +230,7 @@ describe('widget', function() {
226
230
} ) ) ;
227
231
228
232
229
- describe ( 'a' , inject ( function ( $rootScope , $compile ) {
233
+ describe ( 'a' , function ( ) {
230
234
it ( 'should prevent default action to be executed when href is empty' ,
231
235
inject ( function ( $rootScope , $compile ) {
232
236
var orgLocation = document . location . href ,
@@ -261,10 +265,10 @@ describe('widget', function() {
261
265
262
266
expect ( document . location . href ) . toEqual ( orgLocation ) ;
263
267
} ) ) ;
264
- } ) ) ;
268
+ } ) ;
265
269
266
270
267
- describe ( '@ng:repeat' , inject ( function ( $rootScope , $compile ) {
271
+ describe ( '@ng:repeat' , function ( ) {
268
272
it ( 'should ng:repeat over array' , inject ( function ( $rootScope , $compile ) {
269
273
var element = $compile (
270
274
'<ul>' +
@@ -292,6 +296,7 @@ describe('widget', function() {
292
296
expect ( element . text ( ) ) . toEqual ( 'brad;' ) ;
293
297
} ) ) ;
294
298
299
+
295
300
it ( 'should ng:repeat over object' , inject ( function ( $rootScope , $compile ) {
296
301
var element = $compile (
297
302
'<ul>' +
@@ -302,6 +307,7 @@ describe('widget', function() {
302
307
expect ( element . text ( ) ) . toEqual ( 'misko:swe;shyam:set;' ) ;
303
308
} ) ) ;
304
309
310
+
305
311
it ( 'should not ng:repeat over parent properties' , inject ( function ( $rootScope , $compile ) {
306
312
var Class = function ( ) { } ;
307
313
Class . prototype . abc = function ( ) { } ;
@@ -317,6 +323,7 @@ describe('widget', function() {
317
323
expect ( element . text ( ) ) . toEqual ( 'name:value;' ) ;
318
324
} ) ) ;
319
325
326
+
320
327
it ( 'should error on wrong parsing of ng:repeat' , inject ( function ( $rootScope , $compile , $log ) {
321
328
expect ( function ( ) {
322
329
var element = $compile ( '<ul><li ng:repeat="i dont parse"></li></ul>' ) ( $rootScope ) ;
@@ -325,6 +332,7 @@ describe('widget', function() {
325
332
$log . error . logs . shift ( ) ;
326
333
} ) ) ;
327
334
335
+
328
336
it ( 'should expose iterator offset as $index when iterating over arrays' ,
329
337
inject ( function ( $rootScope , $compile ) {
330
338
var element = $compile (
@@ -336,6 +344,7 @@ describe('widget', function() {
336
344
expect ( element . text ( ) ) . toEqual ( 'misko0|shyam1|frodo2|' ) ;
337
345
} ) ) ;
338
346
347
+
339
348
it ( 'should expose iterator offset as $index when iterating over objects' ,
340
349
inject ( function ( $rootScope , $compile ) {
341
350
var element = $compile (
@@ -347,6 +356,7 @@ describe('widget', function() {
347
356
expect ( element . text ( ) ) . toEqual ( 'frodo:f0|misko:m1|shyam:s2|' ) ;
348
357
} ) ) ;
349
358
359
+
350
360
it ( 'should expose iterator position as $position when iterating over arrays' ,
351
361
inject ( function ( $rootScope , $compile ) {
352
362
var element = $compile (
@@ -367,6 +377,7 @@ describe('widget', function() {
367
377
expect ( element . text ( ) ) . toEqual ( 'misko:first|shyam:last|' ) ;
368
378
} ) ) ;
369
379
380
+
370
381
it ( 'should expose iterator position as $position when iterating over objects' ,
371
382
inject ( function ( $rootScope , $compile ) {
372
383
var element = $compile (
@@ -384,6 +395,7 @@ describe('widget', function() {
384
395
expect ( element . text ( ) ) . toEqual ( 'misko:m:first|shyam:s:last|' ) ;
385
396
} ) ) ;
386
397
398
+
387
399
it ( 'should ignore $ and $$ properties' , inject ( function ( $rootScope , $compile ) {
388
400
var element = $compile ( '<ul><li ng:repeat="i in items">{{i}}|</li></ul>' ) ( $rootScope ) ;
389
401
$rootScope . items = [ 'a' , 'b' , 'c' ] ;
@@ -394,6 +406,7 @@ describe('widget', function() {
394
406
expect ( element . text ( ) ) . toEqual ( 'a|b|c|' ) ;
395
407
} ) ) ;
396
408
409
+
397
410
it ( 'should repeat over nested arrays' , inject ( function ( $rootScope , $compile ) {
398
411
var element = $compile (
399
412
'<ul>' +
@@ -407,6 +420,7 @@ describe('widget', function() {
407
420
expect ( element . text ( ) ) . toEqual ( 'a|b|Xc|d|X' ) ;
408
421
} ) ) ;
409
422
423
+
410
424
it ( 'should ignore non-array element properties when iterating over an array' ,
411
425
inject ( function ( $rootScope , $compile ) {
412
426
var element = $compile ( '<ul><li ng:repeat="item in array">{{item}}|</li></ul>' ) ( $rootScope ) ;
@@ -418,6 +432,7 @@ describe('widget', function() {
418
432
expect ( element . text ( ) ) . toBe ( 'a|b|c|' ) ;
419
433
} ) ) ;
420
434
435
+
421
436
it ( 'should iterate over non-existent elements of a sparse array' ,
422
437
inject ( function ( $rootScope , $compile ) {
423
438
var element = $compile ( '<ul><li ng:repeat="item in array">{{item}}|</li></ul>' ) ( $rootScope ) ;
@@ -429,6 +444,7 @@ describe('widget', function() {
429
444
expect ( element . text ( ) ) . toBe ( 'a|b|||c||d|' ) ;
430
445
} ) ) ;
431
446
447
+
432
448
it ( 'should iterate over all kinds of types' , inject ( function ( $rootScope , $compile ) {
433
449
var element = $compile ( '<ul><li ng:repeat="item in array">{{item}}|</li></ul>' ) ( $rootScope ) ;
434
450
$rootScope . array = [ 'a' , 1 , null , undefined , { } ] ;
@@ -456,7 +472,8 @@ describe('widget', function() {
456
472
lis = element . find ( 'li' ) ;
457
473
} ) ) ;
458
474
459
- it ( 'should preserve the order of elements' , inject ( function ( $rootScope , $compile ) {
475
+
476
+ it ( 'should preserve the order of elements' , inject ( function ( $rootScope ) {
460
477
$rootScope . items = [ a , c , d ] ;
461
478
$rootScope . $digest ( ) ;
462
479
var newElements = element . find ( 'li' ) ;
@@ -465,7 +482,8 @@ describe('widget', function() {
465
482
expect ( newElements [ 2 ] ) . not . toEqual ( lis [ 1 ] ) ;
466
483
} ) ) ;
467
484
468
- it ( 'should support duplicates' , inject ( function ( $rootScope , $compile ) {
485
+
486
+ it ( 'should support duplicates' , inject ( function ( $rootScope ) {
469
487
$rootScope . items = [ a , a , b , c ] ;
470
488
$rootScope . $digest ( ) ;
471
489
var newElements = element . find ( 'li' ) ;
@@ -490,8 +508,9 @@ describe('widget', function() {
490
508
expect ( newElements [ 3 ] ) . toEqual ( lis [ 3 ] ) ;
491
509
} ) ) ;
492
510
511
+
493
512
it ( 'should remove last item when one duplicate instance is removed' ,
494
- inject ( function ( $rootScope , $compile ) {
513
+ inject ( function ( $rootScope ) {
495
514
$rootScope . items = [ a , a , a ] ;
496
515
$rootScope . $digest ( ) ;
497
516
lis = element . find ( 'li' ) ;
@@ -504,8 +523,9 @@ describe('widget', function() {
504
523
expect ( newElements [ 1 ] ) . toEqual ( lis [ 1 ] ) ;
505
524
} ) ) ;
506
525
526
+
507
527
it ( 'should reverse items when the collection is reversed' ,
508
- inject ( function ( $rootScope , $compile ) {
528
+ inject ( function ( $rootScope ) {
509
529
$rootScope . items = [ a , b , c ] ;
510
530
$rootScope . $digest ( ) ;
511
531
lis = element . find ( 'li' ) ;
@@ -519,7 +539,7 @@ describe('widget', function() {
519
539
expect ( newElements [ 2 ] ) . toEqual ( lis [ 0 ] ) ;
520
540
} ) ) ;
521
541
} ) ;
522
- } ) ) ;
542
+ } ) ;
523
543
524
544
525
545
describe ( '@ng:non-bindable' , function ( ) {
@@ -568,6 +588,7 @@ describe('widget', function() {
568
588
expect ( element . text ( ) ) . toEqual ( 'angular is da best' ) ;
569
589
} ) ) ;
570
590
591
+
571
592
it ( 'should remove all content when location changes to an unknown route' ,
572
593
inject ( function ( $rootScope , $compile , $location , $httpBackend , $route ) {
573
594
$route . when ( '/foo' , { template : 'myUrl1' } ) ;
@@ -583,6 +604,7 @@ describe('widget', function() {
583
604
expect ( $rootScope . $element . text ( ) ) . toEqual ( '' ) ;
584
605
} ) ) ;
585
606
607
+
586
608
it ( 'should chain scopes and propagate evals to the child scope' ,
587
609
inject ( function ( $rootScope , $compile , $location , $httpBackend , $route ) {
588
610
$route . when ( '/foo' , { template : 'myUrl1' } ) ;
@@ -599,6 +621,7 @@ describe('widget', function() {
599
621
expect ( $rootScope . $element . text ( ) ) . toEqual ( 'new parent' ) ;
600
622
} ) ) ;
601
623
624
+
602
625
it ( 'should be possible to nest ng:view in ng:include' , inject ( function ( ) {
603
626
// TODO(vojta): refactor this test
604
627
var injector = angular . injector ( 'ng' , 'ngMock' ) ;
@@ -624,6 +647,7 @@ describe('widget', function() {
624
647
dealoc ( myApp ) ;
625
648
} ) ) ;
626
649
650
+
627
651
it ( 'should initialize view template after the view controller was initialized even when ' +
628
652
'templates were cached' ,
629
653
inject ( function ( $rootScope , $compile , $location , $httpBackend , $route , $browser ) {
@@ -662,6 +686,7 @@ describe('widget', function() {
662
686
expect ( $rootScope . log ) . toEqual ( [ 'parent' , 'init' , 'child' ] ) ;
663
687
} ) ) ;
664
688
689
+
665
690
it ( 'should discard pending xhr callbacks if a new route is requested before the current ' +
666
691
'finished loading' , inject ( function ( $route , $rootScope , $location , $httpBackend ) {
667
692
// this is a test for a bad race condition that affected feedback
@@ -682,6 +707,7 @@ describe('widget', function() {
682
707
expect ( $rootScope . $element . text ( ) ) . toEqual ( '2' ) ;
683
708
} ) ) ;
684
709
710
+
685
711
it ( 'should clear the content when error during xhr request' ,
686
712
inject ( function ( $route , $location , $rootScope , $httpBackend ) {
687
713
$route . when ( '/foo' , { controller : noop , template : 'myUrl1' } ) ;
@@ -696,6 +722,7 @@ describe('widget', function() {
696
722
expect ( $rootScope . $element . text ( ) ) . toBe ( '' ) ;
697
723
} ) ) ;
698
724
725
+
699
726
it ( 'should be async even if served from cache' ,
700
727
inject ( function ( $route , $rootScope , $location , $templateCache , $browser ) {
701
728
$templateCache . put ( 'myUrl1' , [ 200 , 'my partial' , { } ] ) ;
@@ -717,7 +744,6 @@ describe('widget', function() {
717
744
718
745
describe ( 'ng:pluralize' , function ( ) {
719
746
720
-
721
747
describe ( 'deal with pluralized strings without offset' , function ( ) {
722
748
var element ;
723
749
beforeEach ( inject ( function ( $rootScope , $compile ) {
@@ -729,7 +755,8 @@ describe('widget', function() {
729
755
'</ng:pluralize>' ) ( $rootScope ) ;
730
756
} ) ) ;
731
757
732
- it ( 'should show single/plural strings' , inject ( function ( $rootScope , $compile ) {
758
+
759
+ it ( 'should show single/plural strings' , inject ( function ( $rootScope ) {
733
760
$rootScope . email = 0 ;
734
761
$rootScope . $digest ( ) ;
735
762
expect ( element . text ( ) ) . toBe ( 'You have no new email' ) ;
@@ -768,8 +795,7 @@ describe('widget', function() {
768
795
} ) ) ;
769
796
770
797
771
- it ( 'should show single/plural strings with mal-formed inputs' ,
772
- inject ( function ( $rootScope , $compile ) {
798
+ it ( 'should show single/plural strings with mal-formed inputs' , inject ( function ( $rootScope ) {
773
799
$rootScope . email = '' ;
774
800
$rootScope . $digest ( ) ;
775
801
expect ( element . text ( ) ) . toBe ( '' ) ;
@@ -845,4 +871,3 @@ describe('widget', function() {
845
871
} ) ;
846
872
} ) ;
847
873
} ) ;
848
-
0 commit comments