Skip to content

Instantly share code, notes, and snippets.

@sycobuny
Last active August 29, 2015 14:13
Show Gist options
  • Save sycobuny/6ae1dbb55ca8aee418f0 to your computer and use it in GitHub Desktop.
Save sycobuny/6ae1dbb55ca8aee418f0 to your computer and use it in GitHub Desktop.
MyApp = angular.module('my-app', [])
MyApp.run(function($rootScope) {
testFactory.callFakeAJAX().success(function(response) {
console.log(response.data)
})
})
/***********
* MOCKING *
***********/
MyApp.service('mock', function() {
var service = {}
service.response = function(mockReturn) {
return {
success: function(callback) {
callback({
'status': 'success',
'data': mockReturn
})
},
failure: function(callback) {
callback()
}
}
}
return service
})
/*************
* FACTORIES *
*************/
MyApp.factory('testFactory', function(mock) {
var factory = {}
factory.callFakeAJAX = function() {
return mock.response(['hi'])
}
return factory
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment