@@ -26,31 +26,34 @@ describe('angular-meteor.core', function() {
26
26
} ) ;
27
27
28
28
it ( 'should call Tracker.autorun()' , function ( ) {
29
- var stoppable = { stop : jasmine . createSpy ( 'stop' ) } ;
29
+ var stop = jasmine . createSpy ( 'stop' ) ;
30
+ var stoppable = { stop : stop } ;
30
31
spyOn ( Tracker , 'autorun' ) . and . returnValue ( stoppable ) ;
31
32
32
33
scope . autorun ( function ( ) { } ) ;
33
34
expect ( Tracker . autorun ) . toHaveBeenCalled ( ) ;
34
35
} ) ;
35
36
36
37
it ( 'should autostop computation' , function ( ) {
37
- var stoppable = { stop : jasmine . createSpy ( 'stop' ) } ;
38
+ var stop = jasmine . createSpy ( 'stop' ) ;
39
+ var stoppable = { stop : stop } ;
38
40
spyOn ( Tracker , 'autorun' ) . and . returnValue ( stoppable ) ;
39
41
40
42
scope . autorun ( angular . noop ) ;
41
43
scope . $destroy ( ) ;
42
44
43
- expect ( stoppable . stop ) . toHaveBeenCalled ( ) ;
45
+ expect ( stop ) . toHaveBeenCalled ( ) ;
44
46
} ) ;
45
47
46
48
it ( 'should stop computation manually' , function ( ) {
47
- var stoppable = { stop : jasmine . createSpy ( 'stop' ) } ;
49
+ var stop = jasmine . createSpy ( 'stop' ) ;
50
+ var stoppable = { stop : stop } ;
48
51
spyOn ( Tracker , 'autorun' ) . and . returnValue ( stoppable ) ;
49
52
50
53
var computation = scope . autorun ( angular . noop ) ;
51
54
computation . stop ( ) ;
52
55
53
- expect ( stoppable . stop ) . toHaveBeenCalled ( ) ;
56
+ expect ( stop ) . toHaveBeenCalled ( ) ;
54
57
} ) ;
55
58
56
59
it ( 'should call autorun function using view model as context' , function ( ) {
@@ -66,6 +69,18 @@ describe('angular-meteor.core', function() {
66
69
scope . autorun ( angular . noop ) ;
67
70
expect ( scope . $digest ) . toHaveBeenCalled ( ) ;
68
71
} ) ;
72
+
73
+ it ( 'should remove the destroy event listener once the computation has been stopped' , function ( ) {
74
+ var stop = jasmine . createSpy ( 'stop' ) ;
75
+ var stoppable = { stop : stop } ;
76
+ spyOn ( Tracker , 'autorun' ) . and . returnValue ( stoppable ) ;
77
+
78
+ var computation = scope . autorun ( angular . noop ) ;
79
+ computation . stop ( ) ;
80
+ scope . $destroy ( ) ;
81
+
82
+ expect ( stop . calls . count ( ) ) . toEqual ( 1 ) ;
83
+ } ) ;
69
84
} ) ;
70
85
71
86
describe ( 'subscribe()' , function ( ) {
@@ -87,23 +102,25 @@ describe('angular-meteor.core', function() {
87
102
} ) ;
88
103
89
104
it ( 'should autostop subscription' , function ( ) {
90
- var stoppable = { stop : jasmine . createSpy ( 'stop' ) } ;
105
+ var stop = jasmine . createSpy ( 'stop' ) ;
106
+ var stoppable = { stop : stop } ;
91
107
spyOn ( Tracker , 'autorun' ) . and . returnValue ( stoppable ) ;
92
108
93
109
scope . subscribe ( 'test' ) ;
94
110
scope . $destroy ( ) ;
95
111
96
- expect ( stoppable . stop ) . toHaveBeenCalled ( ) ;
112
+ expect ( stop ) . toHaveBeenCalled ( ) ;
97
113
} ) ;
98
114
99
115
it ( 'should stop subscription manually' , function ( ) {
100
- var stoppable = { stop : jasmine . createSpy ( 'stop' ) } ;
116
+ var stop = jasmine . createSpy ( 'stop' ) ;
117
+ var stoppable = { stop : stop } ;
101
118
spyOn ( Tracker , 'autorun' ) . and . returnValue ( stoppable ) ;
102
119
103
120
var subscription = scope . subscribe ( 'test' ) ;
104
121
subscription . stop ( ) ;
105
122
106
- expect ( stoppable . stop ) . toHaveBeenCalled ( ) ;
123
+ expect ( stop ) . toHaveBeenCalled ( ) ;
107
124
} ) ;
108
125
109
126
it ( 'should return subscription ready and subscriptionId properties' , function ( done ) {
0 commit comments