1
- isLoadingBarInjected = (doc ) ->
2
- injected = false
3
- divs = angular .element (doc).find (' div' )
4
- for i in divs
5
- if angular .element (i).attr (' id' ) is ' loading-bar'
6
- injected = true
7
- break
8
- return injected
9
1
10
2
describe ' loadingBarInterceptor Service' , ->
11
3
12
- $http = $httpBackend = $document = $timeout = result = loadingBar = null
4
+ isLoadingBarInjected = () ->
5
+ injected = false
6
+ divs = $rootElement .find (' div' )
7
+ for i in divs
8
+ if angular .element (i).attr (' id' ) is ' loading-bar'
9
+ injected = true
10
+ break
11
+ return injected
12
+
13
+ $http = $httpBackend = $rootElement = $timeout = result = loadingBar = null
13
14
response = {message : ' OK' }
14
15
endpoint = ' /service'
15
16
@@ -19,10 +20,10 @@ describe 'loadingBarInterceptor Service', ->
19
20
return
20
21
21
22
result = null
22
- inject (_$http_ , _$httpBackend_ , _$document_ , _$timeout_ ) ->
23
+ inject (_$http_ , _$httpBackend_ , _$rootElement_ , _$timeout_ ) ->
23
24
$http = _$http_
24
25
$httpBackend = _$httpBackend_
25
- $document = _$document_
26
+ $rootElement = _$rootElement_
26
27
$timeout = _$timeout_
27
28
28
29
beforeEach ->
@@ -35,6 +36,8 @@ describe 'loadingBarInterceptor Service', ->
35
36
return this .actual > low && this .actual < high
36
37
37
38
39
+
40
+
38
41
afterEach ->
39
42
$httpBackend .verifyNoOutstandingRequest ()
40
43
$timeout .verifyNoPendingTasks ()
@@ -158,7 +161,7 @@ describe 'loadingBarInterceptor Service', ->
158
161
159
162
$httpBackend .flush (1 )
160
163
161
- injected = isLoadingBarInjected $document .find (cfpLoadingBar .parentSelector )
164
+ injected = isLoadingBarInjected $rootElement .find (cfpLoadingBar .parentSelector )
162
165
163
166
expect (injected).toBe true
164
167
$httpBackend .flush ()
@@ -172,12 +175,12 @@ describe 'loadingBarInterceptor Service', ->
172
175
$http .get (endpoint)
173
176
174
177
$timeout .flush () # loading bar is animated, so flush timeout
175
- expect (isLoadingBarInjected ($document .find (cfpLoadingBar .parentSelector ))).toBe true
178
+ expect (isLoadingBarInjected ($rootElement .find (cfpLoadingBar .parentSelector ))).toBe true
176
179
177
180
$httpBackend .flush ()
178
181
$timeout .flush ()
179
182
180
- expect (isLoadingBarInjected ($document .find (cfpLoadingBar .parentSelector ))).toBe false
183
+ expect (isLoadingBarInjected ($rootElement .find (cfpLoadingBar .parentSelector ))).toBe false
181
184
182
185
it ' should get and set status' , inject (cfpLoadingBar ) ->
183
186
cfpLoadingBar .start ()
0 commit comments