I have some jasmine unit tests which are 'integration tests' that exercise some core components that are written as angular services. But my components won't call out to the web. My two tests to demonstrate the problem are like this...
[by the way I have a plug in that disables CORS]
it('test http get', function () {
httpGet('http://endpoint.json');
function httpGet(theUrl) {
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, false);
xmlHttp.send(null);
return xmlHttp.responseText;
}
})
it('test angular http get', inject(function($http) {
$http.get('http://endpoint.json').
success(function (data, status, headers, config) {
console.log('success');
}).
error(function (data, status, headers, config) {
console.log('failure');
});
}));
I know this is because of the $httpBackend mocking. However I a need to use the real implementation. I want to use the asynchronous features of jasmine to wait for the response or timeout but I just cannot figure out how to make angular actually make it's calls.
In other new jQuery calls work fine! :-)