@@ -20,34 +20,35 @@ describe('ngHintScopes', function() {
20
20
} ) ;
21
21
22
22
it ( 'should run perf timers for string expressions' , function ( ) {
23
- var calls = hint . emit . calls ;
24
23
scope . $watch ( 'a.b' , function ( ) { } ) ;
25
- expect ( calls . count ( ) ) . toBe ( 0 ) ;
24
+ expect ( hint . emit . calls . count ( ) ) . toBe ( 0 ) ;
26
25
27
26
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 ( {
27
+ var expectedEvent = {
33
28
eventType : 'scope:watch' ,
34
29
id : scope . $id ,
35
30
watch : 'a.b' ,
36
31
time : null
37
- } ) ;
32
+ } ;
33
+ checkMostRecentCall ( 1 , expectedEvent ) ;
34
+ scope . $apply ( ) ;
35
+ checkMostRecentCall ( 2 , expectedEvent ) ;
36
+ } ) ;
37
+
38
+ it ( 'should handle null watchExpression' , function ( ) {
39
+ scope . $watch ( null , function ( ) { } ) ;
40
+ expect ( hint . emit . calls . count ( ) ) . toBe ( 0 ) ;
38
41
39
42
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 ( {
43
+ var expectedEvent = {
45
44
eventType : 'scope:watch' ,
46
45
id : scope . $id ,
47
- watch : 'a.b' ,
46
+ watch : null ,
48
47
time : null
49
- } ) ;
50
-
48
+ } ;
49
+ checkMostRecentCall ( 1 , expectedEvent ) ;
50
+ scope . $apply ( ) ;
51
+ checkMostRecentCall ( 2 , expectedEvent ) ;
51
52
} ) ;
52
53
53
54
if ( angular . version . minor >= 3 ) {
@@ -70,6 +71,17 @@ describe('ngHintScopes', function() {
70
71
expect ( evt ) . toBeUndefined ( ) ;
71
72
} ) ;
72
73
}
74
+
75
+ // the event's time property is set to null before comparison with expectedEvent, so callers
76
+ // should set the time property on expectedEvent to null as well
77
+ function checkMostRecentCall ( expectedCount , expectedEvent ) {
78
+ var calls = hint . emit . calls ;
79
+ var evt = calls . mostRecent ( ) . args [ 1 ] . events [ 0 ] ;
80
+ expect ( calls . count ( ) ) . toBe ( expectedCount ) ;
81
+ expect ( evt . time ) . toEqual ( jasmine . any ( Number ) ) ;
82
+ evt . time = null ;
83
+ expect ( evt ) . toEqual ( expectedEvent ) ;
84
+ }
73
85
} ) ;
74
86
75
87
// TODO: revisit this when I figure out a good way to make this
0 commit comments