Add endofline normalisation for JavaScript files.
[mootools.git] / Specs / Request / Request.JSON.js
blobbd60e8ffc6464d0d7dd41f2658ed6111ad00727f
1 /*
2 ---
3 name: Request.JSON
4 requires: ~
5 provides: ~
6 ...
7 */
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){
16                         requests.push(xhr);
17                 };
18         });
20         afterEach(function(){
21                 this.xhr.restore();
22         });
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',
30                         onComplete: this.spy
31                 }).send({data: {
32                         '__response': response
33                 }});
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});
40         });
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',
48                         onError: this.spy
49                 }).send({data: {
50                         '__response': response
51                 }});
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;}}');
58         });
60 });