in an angular.js tutorial , i found this example of a factory testing :
the module :
angular.module('omdbModule', [])
.factory('omdbApi', function omdbApiFactory() {
return {
search: function() {
//logic to get data return movieData;
}
}
the test (it can be made by two ways : passing an anonymous function with '$provide' as an argument :
angular.mock.module(function($provide){
$provide.factory('omdbApi', function(){
return{
search:function(query){
return movieData;
}
}
});
or just using an object literal :
angular.mock.module({
'omdbApi':{
{ search:function(query){
return movieData;
}
}
});
in both cases i don't understand why the search function had to be redefined in the mock instead of just getting the factory and then automatically access all its properties and methods. I think defining the whole factory in a mock is good in case it doesn't really exist in the module but why this is done when the module and its factory are already defined and they really exist?