it('should have settings from http request',function(){varresult;varexpected={"period":"day","date":"Sat Dec 21 12:56:53 EST 2013",};httpBackend.expectGET('/settings.json').respond(expected);varpromise=settingService.setting();promise.then(function(data){result=data;});httpBackend.flush();expect(result).toEqual(expected);});
it('should have settings from http request',function(){varresult;varexpected={"period":"day","date":"Sat Dec 21 12:56:53 EST 2013",};httpBackend.expectGET('/settings.json').respond(expected);varpromise=settingService.setting();promise.then(function(data){result=data;});httpBackend.flush();expect(result).toEqual(expected);});
对于异常的情况,比如服务器返回了错误,如500,那么最低程度,程序应该可以处理这个异常:
12345678910111213141516
it("should throw error when network expection",function(){varresult,error;httpBackend.expectGET('/settings.json').respond(500);varpromise=settingService.setting();promise.then(function(data){result=data;},function(data){error=data;});httpBackend.flush();expect(result).toBeUndefined();expect(error).toEqual("network error");});
[{"request":{"method":"post","uri":"/resource"},"response":{"status":201,"text":"resource has been created"}},{"request":{"uri":"/resource"},"response":{"status":200,"file":"resources.json"}}]