2011-08-22 22:26:40 +04:00
|
|
|
var vows = require("vows"),
|
2013-03-14 21:03:10 +04:00
|
|
|
load = require("../load"),
|
2013-03-14 23:59:54 +04:00
|
|
|
assert = require("../assert");
|
2011-08-22 22:26:40 +04:00
|
|
|
|
|
|
|
var suite = vows.describe("d3.selection");
|
|
|
|
|
|
|
|
suite.addBatch({
|
|
|
|
"selection": {
|
2013-03-14 23:36:21 +04:00
|
|
|
topic: load("selection/selection").document(),
|
2013-05-01 01:12:02 +04:00
|
|
|
"selects the document element": function(d3) {
|
2013-03-14 21:03:10 +04:00
|
|
|
var selection = d3.selection();
|
2011-08-22 22:26:40 +04:00
|
|
|
assert.equal(selection.length, 1);
|
|
|
|
assert.equal(selection[0].length, 1);
|
2013-05-01 01:12:02 +04:00
|
|
|
assert.equal(selection[0][0].nodeType, 1);
|
|
|
|
assert.equal(selection[0][0].tagName, "HTML");
|
|
|
|
},
|
|
|
|
"the parentNode is also the document element": function(d3) {
|
|
|
|
var parentNode = d3.selection()[0].parentNode;
|
|
|
|
assert.equal(parentNode.nodeType, 1);
|
|
|
|
assert.equal(parentNode.tagName, "HTML");
|
2011-08-22 22:26:40 +04:00
|
|
|
},
|
2013-03-14 21:03:10 +04:00
|
|
|
"is an instanceof d3.selection": function(d3) {
|
|
|
|
assert.instanceOf(d3.selection(), d3.selection);
|
2011-08-22 22:26:40 +04:00
|
|
|
},
|
2013-03-14 21:03:10 +04:00
|
|
|
"subselections are also instanceof d3.selection": function(d3) {
|
|
|
|
assert.instanceOf(d3.selection().select("body"), d3.selection);
|
|
|
|
assert.instanceOf(d3.selection().selectAll("body"), d3.selection);
|
2011-08-22 22:26:40 +04:00
|
|
|
},
|
2013-03-14 21:03:10 +04:00
|
|
|
"selection prototype can be extended": function(d3) {
|
2011-08-22 22:26:40 +04:00
|
|
|
d3.selection.prototype.foo = function(v) { return this.attr("foo", v); };
|
2013-03-14 23:36:21 +04:00
|
|
|
var body = d3.selection().select("body").foo(42);
|
|
|
|
assert.equal(body.attr("foo"), "42");
|
2011-08-22 22:26:40 +04:00
|
|
|
delete d3.selection.prototype.foo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
suite.export(module);
|