0

I'm working on an AngularJS application that makes numerous $http calls. Most of these are working fine: the backends exist and returns the appropriate data. What I'm working on right now makes calls against an incomplete backend.

How can I mock specific calls without messing with or knowing about what's already working?

I've been looking into ngMockE2E, but that knocks out the entire backend. After setting it to pass through, I don't know how to override just the calls I'm working with.

Is there an easier way to go about this?

ricksmt
  • 888
  • 2
  • 13
  • 34
  • Wrap some mock data which is either hard coded or coming from a JSON file into a promise and return the promise. $http calls return promises so wrapping your mock data in a promise matches the behaviour you'll have once the backend is fully implemented – alamoot Apr 07 '16 at 00:53
  • I'm expecting an answer that utilizes $httpBackend to supply the mock data. I can keep that separate from the AngularJS service so it's easy to add/remove/exclude. – ricksmt Apr 07 '16 at 00:59
  • @estus Thank you! That looks like my answer. I'd still wish for something more classy, but that will probably fit my needs. – ricksmt Apr 07 '16 at 02:31

0 Answers0