내 파일 업로드에 https://github.com/danialfarid/angular-file-upload을 사용하고 있습니다. xhr 요청이 progress
이벤트를 수신 할 때 호출되는 progress
메서드를 제공합니다.
xhr.upload.addEventListener('progress', function(e) {
deferred.notify(e);
}, false);
내 문제는 지금 어떻게이 테스트해야 $httpBackend
를 사용 :이 각 파일 업로드의 소스 코드에서입니까? 나는
$httpBackend.expectPOST("http://localhost:9001/").respond('ok');
$httpBackend.expectPOST("http://localhost:9001/").respond(500, 'some error');
와 성공 및 오류 방법을 테스트 할 수 있습니다하지만 난 화재로 약속의 notify
얻을 수 없습니다. 이것을 할 수있는 방법이 있습니까?
$upload.http({url: url, method: 'POST', data: file})
.progress(function(evt) {
// here is more code, that needs to be tested
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);
});
나는 내 응용 프로그램에서 더 많은 코드를 추가했습니다. 진행 이벤트가 발생하면 실행되는 코드를 테스트하고 싶습니다. – 23tux