10 var arr = ["ab", {"de" : "fg"}, "lp"]; |
10 var arr = ["ab", {"de" : "fg"}, "lp"]; |
11 var serializer = new IriSP.JSONSerializer(this.dt); |
11 var serializer = new IriSP.JSONSerializer(this.dt); |
12 |
12 |
13 equal(serializer.serialize(arr), JSON.stringify(arr), "assert that the outputted json is correct"); |
13 equal(serializer.serialize(arr), JSON.stringify(arr), "assert that the outputted json is correct"); |
14 }); |
14 }); |
|
15 |
|
16 test("sync() - callback should get called", function() { |
|
17 this.xhr = this.sandbox.useFakeXMLHttpRequest(); |
|
18 this.requests = []; |
|
19 this.xhr.onCreate = function (request) { |
|
20 this.requests.push(request); |
|
21 }; |
|
22 |
|
23 var response_array = [{ media: 12, content: "Hey there" }]; |
|
24 var response_string = JSON.stringify(response_array); |
|
25 |
|
26 var spy_callback = this.spy(); |
|
27 var ser = new IriSP.JSONSerializer(this.dt, "/url"); |
|
28 |
|
29 ser.sync(spy_callback); |
|
30 |
|
31 equals(this.xhr.requests.length, 1, "the mock ajax object should have received the request"); |
|
32 this.xhr.requests[0].respond(200, { "Content-Type": "application/json" }, |
|
33 response_string); |
|
34 |
|
35 ok(spy_callback.calledOnce, "callback called"); |
|
36 ok(spy_callback.calledWith(response_array), "callback called with correct value"); |
|
37 deepEqual(ser._data, response_array, "the internal variable is initialized to the correct value"); |
|
38 }); |
15 |
39 |
16 }; |
40 }; |