9 describe('Request.JSON', function(){
11 beforeEach(function(){
12 this.spy = jasmine.createSpy();
13 this.xhr = sinon.useFakeXMLHttpRequest();
14 var requests = this.requests = [];
15 this.xhr.onCreate = function(xhr){
24 it('should create a JSON request', function(){
26 var response = '{"ok":true}';
28 this.spy.identity = 'Requst.JSON';
29 this.request = new Request.JSON({
30 url: '../Helpers/request.php',
33 '__response': response
36 this.requests[0].respond(200, {'Content-Type': 'text/json'}, response);
37 expect(this.spy.wasCalled).toBe(true);
39 // checks the first argument from the first call
40 expect(this.spy.argsForCall[0][0]).toEqual({ok: true});
44 it('should fire the error event', function(){
46 var response = '{"ok":function(){invalid;}}';
48 this.spy.identity = 'Requst.JSON error';
49 this.request = new Request.JSON({
50 url: '../Helpers/request.php',
53 '__response': response
56 this.requests[0].respond(200, {'Content-Type': 'text/json'}, response);
57 expect(this.spy.wasCalled).toBe(true);
59 // checks the first argument from the first call
60 expect(this.spy.argsForCall[0][0]).toEqual('{"ok":function(){invalid;}}');