Skip to content

Commit 5f5d8a2

Browse files
committed
Test selection operator return values.
1 parent e7ad8bb commit 5f5d8a2

14 files changed

Lines changed: 79 additions & 2 deletions

test/core/selection-append-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ suite.addBatch({
2828
"propagates data to new element": function(body) {
2929
var data = new Object(), div = body.data([data]).append("div");
3030
assert.strictEqual(div[0][0].__data__, data);
31+
},
32+
"returns a new selection": function(body) {
33+
assert.isFalse(body.append("div") === body);
3134
}
3235
}
3336
});
@@ -77,6 +80,9 @@ suite.addBatch({
7780
var a = new Object(), b = new Object(), span = div.data([a, b]).append("span");
7881
assert.strictEqual(span[0][0].__data__, a);
7982
assert.strictEqual(span[0][1].__data__, b);
83+
},
84+
"returns a new selection": function(div) {
85+
assert.isFalse(div.append("div") === div);
8086
}
8187
}
8288
});

test/core/selection-attr-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ suite.addBatch({
6262
"removes a namespaced attribute as a function": function(body) {
6363
body.attr("xlink:href", "url").attr("xlink:href", function() { return null; });
6464
assert.equal(body.attr("xlink:href"), "");
65+
},
66+
"returns the current selection": function(body) {
67+
assert.isTrue(body.attr("foo", "bar") === body);
6568
}
6669
}
6770
});
@@ -140,6 +143,9 @@ suite.addBatch({
140143
some.attr("href", null).attr("href", "url");
141144
assert.equal(div[0][0].getAttribute("href"), "url");
142145
assert.equal(div[0][1].getAttribute("href"), "");
146+
},
147+
"returns the current selection": function(div) {
148+
assert.isTrue(div.attr("foo", "bar") === div);
143149
}
144150
}
145151
});

test/core/selection-call-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ suite.addBatch({
3030
var s;
3131
body.call(function() { s = this; });
3232
assert.isTrue(s === body);
33+
},
34+
"returns the current selection": function(body) {
35+
assert.isTrue(body.call(function() {}) === body);
3336
}
3437
}
3538
});
@@ -58,6 +61,9 @@ suite.addBatch({
5861
var s;
5962
div.call(function() { s = this; });
6063
assert.isTrue(s === div);
64+
},
65+
"returns the current selection": function(div) {
66+
assert.isTrue(div.call(function() {}) === div);
6167
}
6268
}
6369
});

test/core/selection-classed-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ suite.addBatch({
8080
assert.isFalse(body.classed("foob"));
8181
assert.isFalse(body.classed("bare"));
8282
assert.isFalse(body.classed("rbaz"));
83+
},
84+
"returns the current selection": function(body) {
85+
assert.isTrue(body.classed("foo", true) === body);
8386
}
8487
}
8588
});
@@ -187,6 +190,9 @@ suite.addBatch({
187190
some.attr("class", null).classed("foo", true);
188191
assert.equal(div[0][0].className, "foo");
189192
assert.equal(div[0][1].className, "");
193+
},
194+
"returns the current selection": function(div) {
195+
assert.isTrue(div.classed("foo", true) === div);
190196
}
191197
}
192198
});

test/core/selection-data-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ suite.addBatch({
2626
document.body.__data__ = expected;
2727
body.each(function(d) { actual = d; });
2828
assert.strictEqual(actual, expected);
29+
},
30+
"returns a new selection": function(body) {
31+
assert.isFalse(body.data([1]) === body);
2932
}
3033
}
3134
});
@@ -53,6 +56,9 @@ suite.addBatch({
5356
div[0][1].__data__ = b;
5457
div.each(function(d) { actual.push(d); });
5558
assert.deepEqual(actual, [a, b]);
59+
},
60+
"returns a new selection": function(div) {
61+
assert.isFalse(div.data([0, 1]) === div);
5662
}
5763
}
5864
});

test/core/selection-each-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ suite.addBatch({
3535
body[0][0] = null;
3636
body.each(function() { ++count; });
3737
assert.equal(count, 0);
38+
},
39+
"returns the current selection": function(body) {
40+
assert.isTrue(body.each(function() {}) === body);
3841
}
3942
}
4043
});
@@ -70,6 +73,9 @@ suite.addBatch({
7073
some[0][0] = null;
7174
some.each(function() { ++count; });
7275
assert.equal(count, 1);
76+
},
77+
"returns the current selection": function(div) {
78+
assert.isTrue(div.each(function() {}) === div);
7379
}
7480
}
7581
});

test/core/selection-filter-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ suite.addBatch({
5353
var some = span.filter(function(d, i) { return d & 1; });
5454
assert.isTrue(some[0][0] === span[0][3]);
5555
assert.equal(some.length, 1);
56+
},
57+
"returns a new selection": function(span) {
58+
assert.isFalse(span.filter(function() { return 1; }) === span);
5659
}
5760
}
5861
});

test/core/selection-html-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ suite.addBatch({
5252
document.body.innerHTML = "<h1>foo</h1>";
5353
body.html("bar");
5454
assert.equal(document.body.textContent, "foo");
55+
},
56+
"returns the current selection": function(body) {
57+
assert.isTrue(body.html("foo") === body);
5558
}
5659
}
5760
});
@@ -108,6 +111,9 @@ suite.addBatch({
108111
some.html("bar");
109112
assert.equal(div[0][0].textContent, "foo");
110113
assert.equal(div[0][1].textContent, "bar");
114+
},
115+
"returns the current selection": function(div) {
116+
assert.isTrue(div.html("foo") === div);
111117
}
112118
}
113119
});

test/core/selection-insert-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ suite.addBatch({
3535
"propagates data to new element": function(body) {
3636
var data = new Object(), div = body.data([data]).insert("div");
3737
assert.strictEqual(div[0][0].__data__, data);
38+
},
39+
"returns a new selection": function(body) {
40+
assert.isFalse(body.insert("div") === body);
3841
}
3942
}
4043
});
@@ -84,6 +87,9 @@ suite.addBatch({
8487
var a = new Object(), b = new Object(), span = div.data([a, b]).insert("span");
8588
assert.strictEqual(span[0][0].__data__, a);
8689
assert.strictEqual(span[0][1].__data__, b);
90+
},
91+
"returns a new selection": function(div) {
92+
assert.isFalse(div.insert("div") === div);
8793
}
8894
}
8995
});
@@ -115,6 +121,10 @@ suite.addBatch({
115121
assert.domNull(div[0][0]);
116122
assert.domEqual(div[0][1].parentNode, document.body);
117123
assert.domEqual(div[0][2].parentNode, document.body);
124+
},
125+
"returns a new selection": function(body) {
126+
var enter = body.html("").selectAll("div").data([0, 1]).enter();
127+
assert.isFalse(enter.insert("div") === enter);
118128
}
119129
}
120130
});

test/core/selection-map-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ suite.addBatch({
1515
body.data([42]).map(function(d, i) { return d + i; });
1616
assert.equal(document.body.__data__, 42);
1717
},
18-
"returns the same selection": function(body) {
18+
"returns the current selection": function(body) {
1919
assert.isTrue(body.map(function() { return 1; }) === body);
2020
}
2121
}
@@ -31,7 +31,7 @@ suite.addBatch({
3131
assert.equal(div[0][0].__data__, 42);
3232
assert.equal(div[0][1].__data__, 44);
3333
},
34-
"returns the same selection": function(div) {
34+
"returns the current selection": function(div) {
3535
assert.isTrue(div.map(function() { return 1; }) === div);
3636
},
3737
"ignores null nodes": function(div) {

0 commit comments

Comments
 (0)