forked from d3/d3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatum-test.js
More file actions
87 lines (83 loc) · 2.96 KB
/
Copy pathdatum-test.js
File metadata and controls
87 lines (83 loc) · 2.96 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
var vows = require("vows"),
load = require("../load"),
assert = require("../assert");
var suite = vows.describe("selection.datum");
suite.addBatch({
"select(body)": {
topic: load("selection/datum").document(),
"on a simple page": {
topic: function(d3) {
return d3.select("body");
},
"updates the data according to the specified function": function(body) {
body.data([42]).datum(function(d, i) { return d + i; });
assert.equal(body.node().__data__, 42);
},
"updates the data to the specified constant": function(body) {
body.datum(43);
assert.equal(body.node().__data__, 43);
},
"deletes the data if the function returns null": function(body) {
body.data([42]).datum(function() { return null; });
assert.isFalse("__data__" in body.node());
},
"deletes the data if the constant is null": function(body) {
body.data([42]).datum(null);
assert.isFalse("__data__" in body.node());
},
"returns the current selection": function(body) {
assert.isTrue(body.datum(function() { return 1; }) === body);
assert.isTrue(body.datum(2) === body);
},
"with no arguments, returns the first node's datum": function(body) {
body.data([42]);
assert.equal(body.datum(), 42);
}
}
}
});
suite.addBatch({
"selectAll(div)": {
topic: load("selection/datum").document(),
"on a simple page": {
topic: function(d3) {
return d3.select("body").selectAll("div").data([0, 1]).enter().append("div");
},
"updates the data according to the specified function": function(div) {
div.data([42, 43]).datum(function(d, i) { return d + i; });
assert.equal(div[0][0].__data__, 42);
assert.equal(div[0][1].__data__, 44);
},
"updates the data to the specified constant": function(div) {
div.datum(44);
assert.equal(div[0][0].__data__, 44);
assert.equal(div[0][1].__data__, 44);
},
"deletes the data if the function returns null": function(div) {
div.datum(function() { return null; });
assert.isFalse("__data__" in div[0][0]);
assert.isFalse("__data__" in div[0][1]);
},
"deletes the data if the constant is null": function(div) {
div.datum(null);
assert.isFalse("__data__" in div[0][0]);
assert.isFalse("__data__" in div[0][1]);
},
"returns the current selection": function(div) {
assert.isTrue(div.datum(function() { return 1; }) === div);
assert.isTrue(div.datum(2) === div);
},
"ignores null nodes": function(div) {
var node = div[0][1];
div[0][1] = null;
div.datum(function() { return 1; });
assert.equal(div[0][0].__data__, 1);
assert.equal(node.__data__, 2);
div.datum(43);
assert.equal(div[0][0].__data__, 43);
assert.equal(node.__data__, 2);
}
}
}
});
suite.export(module);