Skip to content

Commit

Permalink
issue #27: added $timeout.flush to tests
Browse files Browse the repository at this point in the history
The extra $timout.flush() accounts for the latency threshold
  • Loading branch information
chieffancypants committed Jan 21, 2014
1 parent c578c17 commit 153144a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/loading-bar-interceptor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ describe 'loadingBarInterceptor Service', ->
result = data

expect(cfpLoadingBar.status()).toBe 0
$timeout.flush()
$timeout.flush()
$httpBackend.flush(1)
expect(cfpLoadingBar.status()).toBe 1
cfpLoadingBar.complete() # set as complete
Expand All @@ -67,6 +69,8 @@ describe 'loadingBarInterceptor Service', ->
result = data

expect(cfpLoadingBar.status()).toBe 0
$timeout.flush()
$timeout.flush()
$httpBackend.flush(1)
expect(cfpLoadingBar.status()).toBe 1
cfpLoadingBar.complete() # set as complete
Expand All @@ -86,6 +90,8 @@ describe 'loadingBarInterceptor Service', ->
result = data

expect(cfpLoadingBar.status()).toBe 0
$timeout.flush()
$timeout.flush()
$httpBackend.flush(1)
expect(cfpLoadingBar.status()).toBe 1
cfpLoadingBar.complete() # set as complete
Expand All @@ -102,7 +108,10 @@ describe 'loadingBarInterceptor Service', ->
$httpBackend.expectPOST(endpoint).respond response
$http.post(endpoint, {message: 'post'}).then (data) ->
result = data

expect(cfpLoadingBar.status()).toBe 0
$timeout.flush()
$timeout.flush()
$httpBackend.flush(1)
expect(cfpLoadingBar.status()).toBe 1
$timeout.flush()
Expand All @@ -111,7 +120,10 @@ describe 'loadingBarInterceptor Service', ->
$httpBackend.expectPOST(endpoint).respond response
$http.post(endpoint, {message: 'post'}).then (data) ->
result = data

expect(cfpLoadingBar.status()).toBe 0
$timeout.flush()
$timeout.flush()
$httpBackend.flush()
expect(cfpLoadingBar.status()).toBe 1
$timeout.flush()
Expand All @@ -125,6 +137,8 @@ describe 'loadingBarInterceptor Service', ->
result = data

expect(cfpLoadingBar.status()).toBe 0
$timeout.flush()
$timeout.flush()
$httpBackend.flush(1)
expect(cfpLoadingBar.status()).toBe 0.5

Expand All @@ -141,6 +155,8 @@ describe 'loadingBarInterceptor Service', ->
$http.get(endpoint)

expect(cfpLoadingBar.status()).toBe 0
$timeout.flush()
$timeout.flush()
$httpBackend.flush(1)
expect(cfpLoadingBar.status()).toBe 0.5
$httpBackend.flush()
Expand Down

0 comments on commit 153144a

Please sign in to comment.