I'm having trouble testing my file transfer code. It keeps saying "File Transfer undefined". I'm not sure if I need to stub the File Transfer?
Below is my code I'm trying to test:
var uploadAttachment = function(url, mediaFile, type, onSuccess, onError) {
var path;
var ft = new FileTransfer();
if(mediaFile.fullPath == undefined){
path = mediaFile;
}else{
path = mediaFile.fullPath;
}
var options = new FileUploadOptions();
options.chunkedMode = true;
options.fileKey = "file";
options.fileName = type;
options.mimeType = "multipart/form-data";
ft.upload(path, url, function(result) {
onSuccess();
}, function(error) {
onError();
}, options);
return true;
};
Below is my current failed jasmine unit test:
describe('appService', function() {
beforeEach(module('msApp.services'));
beforeEach(module('msApp.environment'));
var scope, rootScope, ft, appServiceMock, httpBackendMock, apiURL, user, request, environment, data, actionItemId;
describe('service tests', function() {
beforeEach(inject(function($rootScope, $injector, Environment) {
scope = $rootScope.$new();
httpBackendMock = $injector.get('$httpBackend');
appServiceMock = $injector.get('AppService');
environment = Environment;
rootScope = $rootScope;
//Variables
rootScope.App = {};
rootScope.App.Session = "";
apiURL = "";
user = {};
request = {};
data = {};
actionItemId = "";
}));
afterEach(function() {
httpBackendMock.verifyNoOutstandingExpectation();
httpBackendMock.verifyNoOutstandingRequest();
});
it("Should upload attachment as expected", function(){
spyOn(appServiceMock, 'uploadAttachment').and.callThrough();
var type, url, mediaFile, ft;
var ft = new FileTransfer();
appServiceMock.uploadAttachment(url, mediaFile, type, jasmine.any(Function), jasmine.any(Function));
})
});
});
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire