forked from d3/d3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection-text-test.js
More file actions
109 lines (104 loc) · 3.74 KB
/
Copy pathselection-text-test.js
File metadata and controls
109 lines (104 loc) · 3.74 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require("../env");
require("../../d3");
var vows = require("vows"),
assert = require("assert");
var suite = vows.describe("selection.text");
suite.addBatch({
"select(body)": {
topic: function() {
return d3.select("body").html("");
},
"sets the text content as a string": function(body) {
body.text("Hello, world!");
assert.equal(document.body.textContent, "Hello, world!");
},
"sets the text content as a number": function(body) {
body.text(42);
assert.equal(document.body.textContent, "42");
},
"sets the text content as a function": function(body) {
body.data(["Subject"]).text(function(d, i) { return "Hello, " + d + " " + i + "!"; });
assert.equal(document.body.textContent, "Hello, Subject 0!");
},
"escapes html content to text": function(body) {
body.text("<h1>Hello, world!</h1>");
assert.equal(document.body.textContent, "<h1>Hello, world!</h1>");
assert.equal(document.body.firstChild.nodeType, document.TEXT_NODE);
},
/*
https://github.com/tmpvar/jsdom/issues/276
"clears the text content as null": function(body) {
body.text(null);
assert.equal(document.body.textContent, "");
},
"clears the text content as a function": function(body) {
body.text(function() { return null; });
assert.equal(document.body.textContent, "");
},
*/
"ignores null nodes": function() {
var body = d3.select("body");
body[0][0] = null;
document.body.textContent = "foo";
body.text("bar");
assert.equal(document.body.textContent, "foo");
},
"returns the current selection": function(body) {
assert.isTrue(body.text("hello") === body);
}
}
});
suite.addBatch({
"selectAll(div)": {
topic: function() {
return d3.select("body").html("").selectAll("div").data(d3.range(2)).enter().append("div");
},
"sets the text content as a string": function(div) {
div.text("Hello, world!");
assert.equal(div[0][0].textContent, "Hello, world!");
assert.equal(div[0][1].textContent, "Hello, world!");
},
"sets the text content as a number": function(div) {
div.text(42);
assert.equal(div[0][0].textContent, "42");
assert.equal(div[0][1].textContent, "42");
},
"sets the text content as a function": function(div) {
div.data(["foo", "bar"]).text(function(d, i) { return "Hello, " + d + " " + i + "!"; });
assert.equal(div[0][0].textContent, "Hello, foo 0!");
assert.equal(div[0][1].textContent, "Hello, bar 1!");
},
"escapes html content to text": function(div) {
div.text("<h1>Hello, world!</h1>");
assert.equal(div[0][0].textContent, "<h1>Hello, world!</h1>");
assert.equal(div[0][1].textContent, "<h1>Hello, world!</h1>");
assert.equal(div[0][0].firstChild.nodeType, document.TEXT_NODE);
assert.equal(div[0][1].firstChild.nodeType, document.TEXT_NODE);
},
/*
https://github.com/tmpvar/jsdom/issues/276
"clears the text content as null": function(div) {
div.text(null);
assert.equal(div[0][0].textContent, "");
assert.equal(div[0][1].textContent, "");
},
"clears the text content as a function": function(div) {
div.text(function() { return null; });
assert.equal(dv[0][0].textContent, "");
assert.equal(dv[0][1].textContent, "");
},
*/
"ignores null nodes": function(div) {
div[0][0].textContent = "foo";
var some = d3.selectAll("div");
some[0][0] = null;
some.text("bar");
assert.equal(div[0][0].textContent, "foo");
assert.equal(div[0][1].textContent, "bar");
},
"returns the current selection": function(div) {
assert.isTrue(div.text("hello") === div);
}
}
});
suite.export(module);