aboutsummaryrefslogtreecommitdiffstats
path: root/test/service/xhrSpec.js
diff options
context:
space:
mode:
authorIgor Minar2011-02-15 01:12:45 -0500
committerIgor Minar2011-02-15 11:01:53 -0500
commit1777110958f76ee4be5760e36c96702223385918 (patch)
tree5aa03b246507e66877e5eac69e58e004e244d7a5 /test/service/xhrSpec.js
parentd2089a16335276eecb8d81eb17332c2dff2cf1a2 (diff)
downloadangular.js-1777110958f76ee4be5760e36c96702223385918.tar.bz2
split up services into individual files
- split up services into files under src/service - split up specs into files under test/service - rewrite all specs so that they don't depend on one global forEach - get rid of obsolete code and tests in ng:switch - rename mock $log spec from "$log" to "$log mock"
Diffstat (limited to 'test/service/xhrSpec.js')
-rw-r--r--test/service/xhrSpec.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/service/xhrSpec.js b/test/service/xhrSpec.js
new file mode 100644
index 00000000..35861a92
--- /dev/null
+++ b/test/service/xhrSpec.js
@@ -0,0 +1,47 @@
+describe('$xhr', function() {
+ var scope, $browser, $browserXhr, $log, $xhr, log;
+
+ beforeEach(function(){
+ scope = angular.scope({}, angular.service, { '$log': $log = {} });
+ $browser = scope.$service('$browser');
+ $browserXhr = $browser.xhr;
+ $xhr = scope.$service('$xhr');
+ log = '';
+ });
+
+
+ afterEach(function(){
+ dealoc(scope);
+ });
+
+
+ function callback(code, response) {
+ expect(code).toEqual(200);
+ log = log + toJson(response) + ';';
+ }
+
+
+ it('should forward the request to $browser and decode JSON', function(){
+ $browserXhr.expectGET('/reqGET').respond('first');
+ $browserXhr.expectGET('/reqGETjson').respond('["second"]');
+ $browserXhr.expectPOST('/reqPOST', {post:'data'}).respond('third');
+
+ $xhr('GET', '/reqGET', null, callback);
+ $xhr('GET', '/reqGETjson', null, callback);
+ $xhr('POST', '/reqPOST', {post:'data'}, callback);
+
+ $browserXhr.flush();
+
+ expect(log).toEqual('"third";["second"];"first";');
+ });
+
+
+ it('should handle exceptions in callback', function(){
+ $log.error = jasmine.createSpy('$log.error');
+ $browserXhr.expectGET('/reqGET').respond('first');
+ $xhr('GET', '/reqGET', null, function(){ throw "MyException"; });
+ $browserXhr.flush();
+
+ expect($log.error).wasCalledWith("MyException");
+ });
+});