Tests/Specs: Replace Chai with expect.js for assertions, because of browser support.
[mootools.git] / Specs / Request / Request.JSON.js
blobcdc659f815c79fe93b6750469860bd478caf3667
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(){
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.called).to.equal(true);
39                 // checks the first argument from the first call
40                 expect(this.spy.args[0][0]).to.eql({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.called).to.equal(true);
59                 // checks the first argument from the first call
60                 expect(this.spy.args[0][0]).to.equal('{"ok":function(){invalid;}}');
62         });
64 });