From ee8e981c47a843786500ef2c420bbcd2c878b167 Mon Sep 17 00:00:00 2001 From: Di Peng Date: Fri, 5 Aug 2011 14:22:23 -0700 Subject: doc(xhr): add e2e test for JSONP error handling - add e2e tests - refactor the example by removing clear button and simplifying the code --- src/service/xhr.js | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/src/service/xhr.js b/src/service/xhr.js index 40be270e..224bc57a 100644 --- a/src/service/xhr.js +++ b/src/service/xhr.js @@ -115,16 +115,21 @@ var self = this; this.fetch = function() { - self.clear(); + self.code = null; + self.response = null; + $xhr(self.method, self.url, function(code, response) { self.code = code; self.response = response; + }, function(code, response) { + self.code = code; + self.response = response || "Request failed"; }); }; - this.clear = function() { - self.code = null; - self.response = null; + this.updateModel = function(method, url) { + self.method = method; + self.url = url; }; } FetchCntl.$inject = ['$xhr']; @@ -134,15 +139,38 @@ -
- - - sample - buzz + +
+ + +
code={{code}}
response={{response}}
+ + it('should make xhr GET request', function() { + element(':button:contains("Sample GET")').click(); + element(':button:contains("fetch")').click(); + expect(binding('code')).toBe('code=200'); + expect(binding('response')).toMatch(/angularjs.org/); + }); + + it('should make JSONP request to the Buzz API', function() { + element(':button:contains("Buzz API")').click(); + element(':button:contains("fetch")').click(); + expect(binding('code')).toBe('code=200'); + expect(binding('response')).toMatch(/buzz-feed/); + }); + + it('should make JSONP request to invalid URL and invoke the error handler', + function() { + element(':button:contains("Invalid JSONP")').click(); + element(':button:contains("fetch")').click(); + expect(binding('code')).toBe('code='); + expect(binding('response')).toBe('response=Request failed'); + }); + */ angularServiceInject('$xhr', function($browser, $error, $log, $updateView){ -- cgit v1.2.3