File size: 1,254 Bytes
5fae594
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

describe("error report", function() {

   it('should parse json if json is given as the body', function(){
      var jsonFromServer = {something:'went wrong'};
   
      var report = errorReport(
         0, 
         JSON.stringify(jsonFromServer));          
   
      expect(report.jsonBody).toEqual(jsonFromServer);
   });
   
   it('should not have jsonBody if no body is given', function(){   
      var report = errorReport();          
   
      expect(report.jsonBody).toBeUndefined();      
   });
   
   it('should not have jsonBody if body is given but it is not json', function(){

      var responseFromServer = "<html>blah blah</html>";
   
      var report = errorReport(404, responseFromServer);          
   
      expect(report.jsonBody).toBeUndefined();      
      expect(report.body).toBe(responseFromServer);      
   });
   
   it('should store status code', function(){   
      var report = errorReport(404);          
   
      expect(report.statusCode).toBe(404);      
   });
   
   it('should store thrown thing', function(){
      var thrown = new Error('something bad happened');
      
      var report = errorReport(404, '', thrown);          
   
      expect(report.thrown).toBe(thrown);      
   });         
   
});