Fixing development version number.
[mootools.git] / Specs / Request / Request.JSON.js
blob786416fd3df853144a99b6ba3522ebe8635fca3b
1 /*
2 ---
3 name: Request.JSON
4 requires: ~
5 provides: ~
6 ...
7 */
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){
16                         requests.push(xhr);
17                 };
18         });
20         afterEach(function(){
21                 this.xhr.restore();
22         });
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',
31                         onComplete: this.spy
32                 }).send({data: {
33                         '__response': response
34                 }});
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});
42         });
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',
51                         onError: this.spy
52                 }).send({data: {
53                         '__response': response
54                 }});
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;}}');
62         });
64 });