Open revolunet opened 10 years ago
That's a damn good idea! I'd love to hear your ideas/code on that.
I have a simple (naive?) approach :
angular.module('app', [
'ngCordova',
'ngCordova.mocks.contacts',
'ngCordova.mocks.accelerometer'
]
$mock.when('$cordovaCamera','getPicture',['profile']).inject(function(){
return 'img/test/face.png';
});
On a similar idea, but that's another project, would be to create a kind of "proxy" that relays the cordova calls to your real device, so you can have real device data and behaviour right into your chrome :)
@revolunet The idea of mock custom data is the best. I really like it.
Came looking through issues to post a similar request. Would really love to mock data for desktop testing. Right now, need to put each $cordovaXX
in a service and wrap cordova detection around them. Pretty painful.
I agree, this would be great functionality to have.
@calendee, in the mean time here is a solution using a decorator, which is a little less painful than individual services.
.config(function($provide){
// Wrappers for ngCordova so it doesn't throw errors in the browser
var cordovaCheck = function($delegate, prop){
//This function will check if cordova is present, and if not, set the prop of $delegate to noop
if ( angular.isUndefined(window.cordova) ){
$delegate[prop] = angular.noop;
}
return $delegate;
};
$provide.decorator( '$cordovaDevice', function($delegate){
return cordovaCheck($delegate, 'getUUID')
});
$provide.decorator( '$cordovaSplashscreen', function($delegate){
return cordovaCheck($delegate, 'hide')
});
})
I posted my idea in #307
Hey Very cool initiative guys, thanks :)
Do you plan to offer a solution to override the cordova calls while not in cordova context ? For example, while developing in chrome it would be cool to have a standard way to provide mocks, for example for the ContactApi.
I'd be pleased to help :)