Last active
August 29, 2015 14:04
-
-
Save callmehiphop/45f0884b20e4402e0603 to your computer and use it in GitHub Desktop.
Convenience wrapper for testing HTTP headers
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
function expectRequest (method, url, data) { | |
var $httpBackend; | |
inject(function ($injector) { | |
$httpBackend = $injector.get('$httpBackend'); | |
}); | |
function withHeaders (expectedHeaders) { | |
return $httpBackend.expect(method, url, data, function (actualHeaders) { | |
for (var header in expectedHeaders) { | |
if (actualHeaders[header] !== expectedHeaders[header]) { | |
return false; | |
} | |
} | |
return true; | |
}); | |
} | |
return { | |
withHeaders: withHeaders | |
}; | |
} |
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
it('should do a thing', function () { | |
expectRequest('GET', 'http://place.com/thing') | |
.withHeaders({ | |
Authorization: 'FuzzyMonkeys' | |
}) | |
.respond({ | |
message: 'You are the fuzziest monkey.' | |
}); | |
$http.get('http://place.com/thing', { | |
headers: { | |
Authorization: 'BaldMonkeys' | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment