9 describe('Request.JSON', function(){
11 beforeEach(function(){
12 this.spy = sinon.spy();
13 this.xhr = sinon.useFakeXMLHttpRequest();
14 var requests = this.requests = [];
15 this.xhr.onCreate = function(xhr){
24 it('should create a JSON request', function(){
25 var response = '{"ok":true}';
27 this.spy.identity = 'Requst.JSON';
28 this.request = new Request.JSON({
29 url: '../Helpers/request.php',
32 '__response': response
35 this.requests[0].respond(200, {'Content-Type': 'text/json'}, response);
36 expect(this.spy.called).to.equal(true);
38 // Checks the first argument from the first call.
39 expect(this.spy.args[0][0]).to.eql({ok: true});
42 it('should fire the error event', function(){
43 var response = '{"ok":function(){invalid;}}';
45 this.spy.identity = 'Requst.JSON error';
46 this.request = new Request.JSON({
47 url: '../Helpers/request.php',
50 '__response': response
53 this.requests[0].respond(200, {'Content-Type': 'text/json'}, response);
54 expect(this.spy.called).to.equal(true);
56 // Checks the first argument from the first call.
57 expect(this.spy.args[0][0]).to.equal('{"ok":function(){invalid;}}');