As you know, the built-in function of corner functions is tested inside the module for mocking XHR requests using $ httpBackend - this is nice and useful when writing unit tests.
I recently met a need for a mocking XHR in case of a file upload and found some problems.
Consider the following code:
var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress(event), false); xhr.addEventListener("load", uploadComplete(event), false); xhr.addEventListener("error", uploadError(event), false); xhr.addEventListener("abort", uploadAbort(event), false); xhr.open("POST", 'some url'); xhr.send(someData);
What I want to do is to do unit testing of such code with bullying on XHR requests, but this cannot be done because the $ http service is not used here.
I tried this (and it worked, and it was possible to mock $ httpBackend):
$http({ method: 'POST', url: 'some url', data: someData, headers: {'Content-Type': undefined}, transformRequest: angular.identity}) .then(successCallback, errorCallback);
But in this case, I do not know how to implement the callback "progress" and "abort" callback (they are necessary and necessary if I am working now).
I saw information that the latest Angular supports a progress callback for promises (not sure though it is integrated with the $ http service), but what about canceling the callback?
Any ideas, or maybe you've met something similar before?