Created
June 11, 2014 13:03
-
-
Save jameslafa/f4a915331e376dd0981f to your computer and use it in GitHub Desktop.
AngularJS: serve different responses with $httpBackend inside the same test (auto retry for example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# More details on https://blog.james-lafa.fr/angularjs-how-to-test-a-retry-after-http-error-with-httpbackend/ | |
sessionCalls = 0 | |
$httpBackend.when('POST', '/sessions').respond( (method, url, data, headers) -> | |
if sessionCalls == 0 | |
sessionCalls++ | |
return [200, {"response": 1}, {}] | |
else | |
sessionCalls++ | |
return [200, {"response":0,"auth_token":"HK7i6DRncWdBmq"}, {}] | |
) | |
Backend.createSession() | |
$httpBackend.flush() | |
expect(sessionCalls).toEqual(2) | |
expect(Backend.isLoggedIn()).toBe(true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment