Skip to content

Commit bbb126f

Browse files
committed
Merge pull request d3#324 from jasondavies/tree-test
Another test for empty children arrays.
2 parents ace525c + c7f5846 commit bbb126f

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

test/layout/tree-test.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,31 @@ suite.addBatch({
1111
"tree": {
1212
topic: d3.layout.tree,
1313
"can handle an empty children array": function(tree) {
14-
assert.deepEqual(tree.nodes({children: []}), [
15-
{children: [], depth: 0, x: 0.5, y: 0}
14+
assert.deepEqual(tree.nodes({children: []}).map(layout), [
15+
{depth: 0, x: 0.5, y: 0}
16+
]);
17+
assert.deepEqual(tree.nodes({children: [
18+
{children: []},
19+
{children: [{}]},
20+
{children: [{}]}
21+
]}).map(layout), [
22+
{depth: 0, x: .5, y: 0},
23+
{depth: 1, x: .125, y: 0.5},
24+
{depth: 1, x: .375, y: 0.5},
25+
{depth: 2, x: .375, y: 1},
26+
{depth: 1, x: .875, y: 0.5},
27+
{depth: 2, x: .875, y: 1}
1628
]);
1729
}
1830
}
1931
});
2032

33+
function layout(node) {
34+
return {
35+
depth: node.depth,
36+
x: node.x,
37+
y: node.y
38+
};
39+
}
40+
2141
suite.export(module);

0 commit comments

Comments
 (0)