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