Skip to content

Commit e65d455

Browse files
committed
Reuse global d3's document for xhr test.
1 parent 5627ecd commit e65d455

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

test/xhr/html-test.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
var vows = require("vows"),
2+
jsdom = require("jsdom").jsdom,
3+
d3 = require("../../"),
24
load = require("../load"),
35
xhr = require("../env-xhr"),
46
assert = require("../env-assert"),
5-
jsdom = require("jsdom").jsdom,
6-
document = jsdom("<html><head></head><body></body></html>"),
7-
window = document.createWindow();
7+
document = d3.selection().node()._ownerDocument,
8+
window = document.defaultView;
89

910
// Monkey-patch createRange support to JSDOM.
1011
document.createRange = function() {
@@ -18,31 +19,31 @@ var suite = vows.describe("d3.html");
1819

1920
suite.addBatch({
2021
"html": {
21-
topic: load("xhr/html").sandbox({
22+
topic: load("xhr/html").expression("d3.html").sandbox({
2223
XMLHttpRequest: xhr,
2324
document: document,
2425
window: window
2526
}),
2627

2728
"on a sample file": {
28-
topic: function(d3) {
29+
topic: function(html) {
2930
var cb = this.callback;
30-
d3.html("test/data/sample.html", function(error, document) {
31+
html("test/data/sample.html", function(error, document) {
3132
cb(null, document);
3233
});
3334
},
3435
"invokes the callback with the loaded html": function(document) {
3536
assert.equal(document.getElementsByTagName("H1")[0].textContent, "Hello & world!");
3637
},
37-
"override the mime type to text/html": function(xml) {
38+
"override the mime type to text/html": function(document) {
3839
assert.equal(xhr._last._info.mimeType, "text/html");
3940
}
4041
},
4142

4243
"on a file that does not exist": {
43-
topic: function(d3) {
44+
topic: function(html) {
4445
var cb = this.callback;
45-
d3.html("//does/not/exist.html", function(error, document) {
46+
html("//does/not/exist.html", function(error, document) {
4647
cb(null, document);
4748
});
4849
},

0 commit comments

Comments
 (0)