samedi 29 mars 2014

Mocking HTTP calls when using the ArcGIS JavaScript API


Vote count:

0




I'm an AngularJS developer, so most of my unit tests that rely on HTTP use the $http service and the mock $httpBackend service.


I'm integrating some code with the ArcGIS JavaScript API, which makes HTTP calls, but obviously doesn't use $http, so my mock backend isn't going to help me isolate my unit tests.


For example, when I construct a WMSLayer object...



require(['esri/layers/WMSLayer'], function(WMSLayer) {
var layer = new WMSLayer('/mock-endpoint');
}


it's going to try to make a real HTTP connection to the mock endpoint. Is there an easy way to mock this out so it doesn't do that and instead goes to a fake backend?


Some ideas that I've come up with:



  • I know that internally the ArcGIS API uses Dojo. I'm not as familiar with Dojo -- is there an equivalent to $httpBackend?

  • I'm using Jasmine as my unit test runner. I could possibly replace the Ajax calls with my own.

  • I could potentially do something with the proxyUrl settings to bounce back requests, but then I'm getting into some server side code and I'd like to keep things mostly client side.



asked 18 secs ago

austin

2,843





Aucun commentaire:

Enregistrer un commentaire