@@ -10,6 +10,68 @@ describe('ngHintScopes', function() {
10
10
$rootScope = _$rootScope_ ;
11
11
} ) ) ;
12
12
13
+ describe ( 'scope.$watch' , function ( ) {
14
+ var scope ;
15
+
16
+ beforeEach ( function ( ) {
17
+ scope = $rootScope . $new ( ) ;
18
+ scope . a = { b : 'hello' } ;
19
+ spyOn ( hint , 'emit' ) ;
20
+ } ) ;
21
+
22
+ it ( 'should run perf timers for string expressions' , function ( ) {
23
+ var calls = hint . emit . calls ;
24
+ scope . $watch ( 'a.b' , function ( ) { } ) ;
25
+ expect ( calls . count ( ) ) . toBe ( 0 ) ;
26
+
27
+ scope . $apply ( ) ;
28
+ var evt = calls . mostRecent ( ) . args [ 1 ] . events [ 0 ] ;
29
+ expect ( calls . count ( ) ) . toBe ( 1 ) ;
30
+ expect ( evt . time ) . toEqual ( jasmine . any ( Number ) ) ;
31
+ evt . time = null
32
+ expect ( evt ) . toEqual ( {
33
+ eventType : 'scope:watch' ,
34
+ id : scope . $id ,
35
+ watch : 'a.b' ,
36
+ time : null
37
+ } ) ;
38
+
39
+ scope . $apply ( ) ;
40
+ expect ( calls . count ( ) ) . toBe ( 2 ) ;
41
+ var evt = calls . mostRecent ( ) . args [ 1 ] . events [ 0 ] ;
42
+ expect ( evt . time ) . toEqual ( jasmine . any ( Number ) ) ;
43
+ evt . time = null
44
+ expect ( evt ) . toEqual ( {
45
+ eventType : 'scope:watch' ,
46
+ id : scope . $id ,
47
+ watch : 'a.b' ,
48
+ time : null
49
+ } ) ;
50
+
51
+ } ) ;
52
+
53
+ if ( angular . version . minor >= 3 ) {
54
+ it ( 'should not run perf timers for one time bind expressions' , function ( ) {
55
+ var calls = hint . emit . calls ;
56
+ scope . $watch ( '::a.b' , function ( ) { } ) ;
57
+ expect ( calls . count ( ) ) . toBe ( 0 ) ;
58
+
59
+ scope . $apply ( ) ;
60
+ var evt = calls . mostRecent ( ) . args [ 1 ] . events [ 0 ] ;
61
+ // this is the watch angular registers and deregisters on $$postDigest
62
+ // for one time watch expressions
63
+ expect ( calls . count ( ) ) . toBe ( 1 ) ;
64
+ expect ( evt . eventType ) . toBe ( 'scope:watch' ) ;
65
+ expect ( evt . watch ) . toBe ( 'oneTimeWatch' ) ;
66
+
67
+ scope . $apply ( )
68
+ var evt = calls . mostRecent ( ) . args [ 1 ] . events [ 0 ] ;
69
+ expect ( calls . count ( ) ) . toBe ( 2 ) ;
70
+ expect ( evt ) . toBeUndefined ( ) ;
71
+ } ) ;
72
+ }
73
+ } ) ;
74
+
13
75
// TODO: revisit this when I figure out a good way to make this
14
76
// perform; see: https://github.com/angular/angular-hint-scopes/issues/2
15
77
// describe('$rootScope.$watch', function() {
0 commit comments