2011-08-13 21:26:24 +04:00
|
|
|
require("../env");
|
|
|
|
|
|
|
|
var vows = require("vows"),
|
|
|
|
assert = require("assert");
|
|
|
|
|
|
|
|
var suite = vows.describe("selection.call");
|
|
|
|
|
|
|
|
suite.addBatch({
|
|
|
|
"select(body)": {
|
|
|
|
topic: function() {
|
|
|
|
return d3.select("body").html("");
|
|
|
|
},
|
|
|
|
"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);
|
2011-08-14 05:40:38 +04:00
|
|
|
},
|
|
|
|
"returns the current selection": function(body) {
|
|
|
|
assert.isTrue(body.call(function() {}) === body);
|
2011-08-13 21:26:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
suite.addBatch({
|
|
|
|
"selectAll(div)": {
|
|
|
|
topic: function() {
|
|
|
|
return d3.select("body").html("").selectAll("div").data(d3.range(2)).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);
|
2011-08-14 05:40:38 +04:00
|
|
|
},
|
|
|
|
"returns the current selection": function(div) {
|
|
|
|
assert.isTrue(div.call(function() {}) === div);
|
2011-08-13 21:26:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
suite.export(module);
|