Wednesday, 10 June 2015

protractor e2e test $httpBackend when JSONP(url)

when you make a api call by JSONP you can:

$http({
            method: 'JSONP',
            url: '//api.flickr.com/services/feeds/photos_public.gne?tagmode=all&format=json',
            params: {
                   'jsoncallback': 'JSON_CALLBACK'
            }
         
          }).success(function(data, status, headers, config) {
                getSuccessHandler(data, deferred);
            }).
            error(function(data, status, headers, config) {
                getErrorHandler(data, deferred);
            });



However, you will have issue with this call when you do e2e test with $httpBackend.

$httpBackend not able to catch your api call by the url. (GET, POST do not have this issue)

The solution is change the url and remove the params from the call:

$http({
            method: 'JSONP',
            url: '//api.flickr.com/services/feeds/photos_public.gne?tagmode=all&format=json&jsoncallback=JSON_CALLBACK'
          }).success(function(data, status, headers, config) {
                getSuccessHandler(data, deferred);
            }).
            error(function(data, status, headers, config) {
                getErrorHandler(data, deferred);
            });






useful link:

https://books.google.co.uk/books?id=t-laBAAAQBAJ&pg=PT194&lpg=PT194&dq=$httpBackend+when+JSONP%28url%29&source=bl&ots=BE2L4VemwV&sig=S5onxhoDLLcL8vEQPGGFT0e3Nak&hl=en&sa=X&ei=VJl2VbDjEaSr7Aa1z4CYAg&ved=0CCAQ6AEwADgK#v=onepage&q=%24httpBackend%20when%20JSONP(url)&f=false














No comments:

Post a comment