forked from d3/d3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall-test.js
More file actions
75 lines (71 loc) · 2.23 KB
/
Copy pathcall-test.js
File metadata and controls
75 lines (71 loc) · 2.23 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
var vows = require("vows"),
load = require("../load"),
assert = require("../assert");
var suite = vows.describe("selection.call");
suite.addBatch({
"select(body)": {
topic: load("selection/call").document(),
"on a simple page": {
topic: function(d3) {
return d3.select("body");
},
"calls the function once": function(body) {
var count = 0;
body.call(function() { ++count; });
assert.equal(count, 1);
},
"passes any optional arguments": function(body) {
var abc;
body.call(function(selection, a, b, c) { abc = [a, b, c]; }, "a", "b", "c");
assert.deepEqual(abc, ["a", "b", "c"]);
},
"passes the selection as the first argument": function(body) {
var s;
body.call(function(selection) { s = selection; });
assert.isTrue(s === body);
},
"uses the selection as the context": function(body) {
var s;
body.call(function() { s = this; });
assert.isTrue(s === body);
},
"returns the current selection": function(body) {
assert.isTrue(body.call(function() {}) === body);
}
}
}
});
suite.addBatch({
"selectAll(div)": {
topic: load("selection/call").document(),
"on a simple page": {
topic: function(d3) {
return d3.select("body").selectAll("div").data([0, 1]).enter().append("div");
},
"calls the function once": function(div) {
var count = 0;
div.call(function() { ++count; });
assert.equal(count, 1);
},
"passes any optional arguments": function(div) {
var abc;
div.call(function(selection, a, b, c) { abc = [a, b, c]; }, "a", "b", "c");
assert.deepEqual(abc, ["a", "b", "c"]);
},
"passes the selection as the first argument": function(div) {
var s;
div.call(function(selection) { s = selection; });
assert.isTrue(s === div);
},
"uses the selection as the context": function(div) {
var s;
div.call(function() { s = this; });
assert.isTrue(s === div);
},
"returns the current selection": function(div) {
assert.isTrue(div.call(function() {}) === div);
}
}
}
});
suite.export(module);