|
1 require("../env"); |
|
2 require("../../d3"); |
|
3 |
|
4 var vows = require("vows"), |
|
5 assert = require("assert"); |
|
6 |
|
7 var suite = vows.describe("d3.xhr"); |
|
8 |
|
9 suite.addBatch({ |
|
10 "xhr": { |
|
11 topic: function() { |
|
12 var cb = this.callback; |
|
13 return d3.xhr("examples/data/sample.txt", function(req) { |
|
14 cb(null, req); |
|
15 }); |
|
16 }, |
|
17 "makes an asynchronous HTTP request": function(req) { |
|
18 assert.equal(req._info.url, "examples/data/sample.txt"); |
|
19 assert.isTrue(req._info.async); |
|
20 }, |
|
21 "invokes the callback with the request object": function(req) { |
|
22 assert.equal(req.responseText, "Hello, world!\n"); |
|
23 }, |
|
24 "does not override the mime type by default": function(req) { |
|
25 assert.isUndefined(req._info.mimeType); |
|
26 }, |
|
27 "waits until the request is done": function(req) { |
|
28 assert.equal(req.readyState, 4); |
|
29 assert.equal(req.status, 200); |
|
30 }, |
|
31 "": { |
|
32 topic: function() { |
|
33 var cb = this.callback; |
|
34 return d3.xhr("examples/data/sample.txt", "text/plain", function(req) { |
|
35 cb(null, req); |
|
36 }); |
|
37 }, |
|
38 "observes the optional mime type": function(req) { |
|
39 assert.equal(req._info.mimeType, "text/plain"); |
|
40 } |
|
41 }, |
|
42 " ": { |
|
43 topic: function() { |
|
44 var cb = this.callback; |
|
45 return d3.xhr("//does/not/exist.txt", function(req) { |
|
46 cb(null, req); |
|
47 }); |
|
48 }, |
|
49 "invokes the callback with null when an error occurs": function(req) { |
|
50 assert.isNull(req); |
|
51 } |
|
52 } |
|
53 } |
|
54 }); |
|
55 |
|
56 suite.export(module); |