@@ -11,7 +11,7 @@ describe('ngIdle', function() {
11
11
} ) ;
12
12
13
13
describe ( 'idle' , function ( ) {
14
- var $idleProvider , $interval , $rootScope , $log , $document , $keepalive ;
14
+ var $idleProvider , $interval , $rootScope , $log , $document , $keepalive , $timeout ;
15
15
var DEFAULTIDLEDURATION = 20 * 60 * 1000 , DEFAULTWARNINGDURATION = 30 * 1000 ;
16
16
17
17
beforeEach ( module ( 'ngIdle.idle' ) ) ;
@@ -26,11 +26,12 @@ describe('ngIdle', function() {
26
26
27
27
module ( 'app' ) ;
28
28
29
- inject ( function ( _$interval_ , _$log_ , _$rootScope_ , _$document_ ) {
29
+ inject ( function ( _$interval_ , _$log_ , _$rootScope_ , _$document_ , _$timeout_ ) {
30
30
$rootScope = _$rootScope_ ;
31
31
$interval = _$interval_ ;
32
32
$log = _$log_ ;
33
33
$document = _$document_ ;
34
+ $timeout = _$timeout_ ;
34
35
} ) ;
35
36
36
37
$keepalive = {
@@ -164,6 +165,7 @@ describe('ngIdle', function() {
164
165
$idle . watch ( ) ;
165
166
166
167
$interval . flush ( DEFAULTIDLEDURATION ) ;
168
+ $timeout . flush ( ) ;
167
169
168
170
expect ( $rootScope . $broadcast ) . toHaveBeenCalledWith ( '$idleStart' ) ;
169
171
expect ( $keepalive . stop ) . toHaveBeenCalled ( ) ;
@@ -175,6 +177,7 @@ describe('ngIdle', function() {
175
177
$idle . watch ( ) ;
176
178
177
179
$interval . flush ( DEFAULTIDLEDURATION ) ;
180
+ $timeout . flush ( ) ;
178
181
179
182
$idle . watch ( ) ;
180
183
@@ -189,15 +192,24 @@ describe('ngIdle', function() {
189
192
$idle . watch ( ) ;
190
193
191
194
$interval . flush ( DEFAULTIDLEDURATION ) ;
195
+ $timeout . flush ( ) ;
192
196
193
197
expect ( $rootScope . $broadcast ) . toHaveBeenCalledWith ( '$idleStart' ) ;
194
198
expect ( $rootScope . $broadcast ) . toHaveBeenCalledWith ( '$idleWarn' , 3 ) ;
199
+
195
200
$interval . flush ( 1000 ) ;
201
+ $timeout . flush ( ) ;
202
+
196
203
expect ( $rootScope . $broadcast ) . toHaveBeenCalledWith ( '$idleWarn' , 2 ) ;
204
+
197
205
$interval . flush ( 1000 ) ;
206
+ $timeout . flush ( ) ;
207
+
198
208
expect ( $rootScope . $broadcast ) . toHaveBeenCalledWith ( '$idleWarn' , 1 ) ;
199
209
200
210
$interval . flush ( 1000 ) ;
211
+ $timeout . flush ( ) ;
212
+
201
213
expect ( $rootScope . $broadcast ) . toHaveBeenCalledWith ( '$idleTimeout' ) ;
202
214
203
215
// ensure idle interval doesn't keep executing after $idleStart
@@ -214,6 +226,7 @@ describe('ngIdle', function() {
214
226
$interval . flush ( DEFAULTIDLEDURATION ) ;
215
227
216
228
$interval . flush ( 1000 ) ;
229
+ $timeout . flush ( ) ;
217
230
218
231
expect ( $idle . idling ( ) ) . toBe ( true ) ;
219
232
0 commit comments