I am currently utilizing a file upload feature from https://github.com/danialfarid/angular-file-upload in my project. This library includes a progress
method that is triggered when the xhr request receives the progress
event. Here is an excerpt from the source code of angular-file-upload:
xhr.upload.addEventListener('progress', function(e) {
deferred.notify(e);
}, false);
My challenge now lies in testing this using $httpBackend
. I am able to test the success and error scenarios with
$httpBackend.expectPOST("http://localhost:9001/").respond('ok');
$httpBackend.expectPOST("http://localhost:9001/").respond(500, 'some error');
However, I am struggling to trigger the notify
function of the promise. Is there a way to achieve this?
EDIT
The specific section I want to test resides within the progress
method:
$upload.http({url: url, method: 'POST', data: file})
.progress(function(evt) {
// There is additional code here that requires testing
self.$deferreds.upload.notify((100.0 * evt.loaded / evt.total).toFixed(2));
}).success(function(data, status, headers, config) {
self.$deferreds.upload.resolve(data);
}).error(function(response) {
self.$deferreds.upload.reject(response);
});