I'm writing unit tests for my Ionic app and encountered a problem when testing camera related functions. My code uses two global variables set by cordova.js: Camera and CameraPopoverOptions. Since the file only gets inserted on actual mobile devices, both of them are undefined when the test needs them. Where should I get these two variables for tests or should I just find out their values and hardcode them?
.factory('Camera', ['$q', '$cordovaCamera', '$window', function($q, $cordovaCamera, $window) {
return {
getPicture: function(options) {
if(!$window.cordova) {
// We are in dev mode, let's return a kickass Ferrari
var q = $q.defer();
q.resolve('/img/ferrari.jpg');
return q.promise;
}
var options = {
quality : 75,
destinationType : Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : false,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 1024,
targetHeight: 1024,
correctOrientation: true,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
// Returns a promise
return $cordovaCamera.getPicture(options);
}
}
}])