I have a large existing SPA application which using REST/JSON calls to get/save data to the database.
I was recently introduced to AngularJS and i think its really cool, especially its mocking feature.
However, up until now i'm failing to grasp how can i mock a backend call end-to-end.
What I'm looking for is a simple application with the html, the controllers and the mock layer the demostrate how to do it with in the most simple basic way. The example that i saw on jsFiddle didn't really make it.
i put my test app online (http://plnkr.co/edit/HcaKeKqbHKZsvmuDt5tR). As you can see, this is one is from Angular website, with minor addition (the reset pwd function). What i want to do is to add a module that can help me to test the reset pwd functionality, by intercepting the jsonp call (or any other json call the i have in my app), and instead, return a static json data object.
http://plnkr.co/edit/HcaKeKqbHKZsvmuDt5tR
Can anybody help me out here?
I think you're looking how to use $httpBackend service. Documentation: http://docs.angularjs.org/api/ngMockE2E.$httpBackend and http://docs.angularjs.org/api/ngMock.$httpBackend has quite lot examples.
I've created Plunker example with sample mocked hackend: http://plnkr.co/edit/R4Bxs4u7n2iNjIMP0izh?p=preview
Mocking is done by:
$httpBackend.whenGET('some.json').respond({name:"MyName"});