3
var vows = require("vows"),
4
assert = require("assert");
6
var suite = vows.describe("selection.text");
11
return d3.select("body").html("");
13
"sets the text content as a string": function(body) {
14
body.text("Hello, world!");
15
assert.equal(document.body.textContent, "Hello, world!");
17
"sets the text content as a number": function(body) {
19
assert.equal(document.body.textContent, "42");
21
"sets the text content as a function": function(body) {
22
body.data(["Subject"]).text(function(d, i) { return "Hello, " + d + " " + i + "!"; });
23
assert.equal(document.body.textContent, "Hello, Subject 0!");
25
"escapes html content to text": function(body) {
26
body.text("<h1>Hello, world!</h1>");
27
assert.equal(document.body.textContent, "<h1>Hello, world!</h1>");
28
assert.equal(document.body.firstChild.nodeType, document.TEXT_NODE);
30
"clears the text content as null": function(body) {
32
assert.equal(document.body.textContent, "");
34
"clears the text content as undefined": function(body) {
36
assert.equal(document.body.textContent, "");
38
"clears the text content as a function returning null": function(body) {
39
body.text(function() { return null; });
40
assert.equal(document.body.textContent, "");
42
"clears the text content as a function returning undefined": function(body) {
43
body.text(function() { return undefined; });
44
assert.equal(document.body.textContent, "");
46
"ignores null nodes": function() {
47
var body = d3.select("body");
49
document.body.textContent = "foo";
51
assert.equal(document.body.textContent, "foo");
53
"returns the current selection": function(body) {
54
assert.isTrue(body.text("hello") === body);
62
return d3.select("body").html("").selectAll("div").data(d3.range(2)).enter().append("div");
64
"sets the text content as a string": function(div) {
65
div.text("Hello, world!");
66
assert.equal(div[0][0].textContent, "Hello, world!");
67
assert.equal(div[0][1].textContent, "Hello, world!");
69
"sets the text content as a number": function(div) {
71
assert.equal(div[0][0].textContent, "42");
72
assert.equal(div[0][1].textContent, "42");
74
"sets the text content as a function": function(div) {
75
div.data(["foo", "bar"]).text(function(d, i) { return "Hello, " + d + " " + i + "!"; });
76
assert.equal(div[0][0].textContent, "Hello, foo 0!");
77
assert.equal(div[0][1].textContent, "Hello, bar 1!");
79
"escapes html content to text": function(div) {
80
div.text("<h1>Hello, world!</h1>");
81
assert.equal(div[0][0].textContent, "<h1>Hello, world!</h1>");
82
assert.equal(div[0][1].textContent, "<h1>Hello, world!</h1>");
83
assert.equal(div[0][0].firstChild.nodeType, document.TEXT_NODE);
84
assert.equal(div[0][1].firstChild.nodeType, document.TEXT_NODE);
87
https://github.com/tmpvar/jsdom/issues/276
88
"clears the text content as null": function(div) {
90
assert.equal(div[0][0].textContent, "");
91
assert.equal(div[0][1].textContent, "");
93
"clears the text content as a function": function(div) {
94
div.text(function() { return null; });
95
assert.equal(dv[0][0].textContent, "");
96
assert.equal(dv[0][1].textContent, "");
99
"ignores null nodes": function(div) {
100
div[0][0].textContent = "foo";
101
var some = d3.selectAll("div");
104
assert.equal(div[0][0].textContent, "foo");
105
assert.equal(div[0][1].textContent, "bar");
107
"returns the current selection": function(div) {
108
assert.isTrue(div.text("hello") === div);
113
suite.export(module);