Skip to content

Commit

Permalink
Add tests for allowing callbacks to return a transition.
Browse files Browse the repository at this point in the history
  • Loading branch information
curran committed May 25, 2021
1 parent a7ab8a2 commit bb4da56
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/selection/join-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,21 @@ tape("selection.join(…) reorders nodes to match the data", function(test) {
test.equal(document.body.innerHTML, "<p>0</p><p>3</p><p>1</p><p>2</p><p>4</p>");
test.end();
});

function mockTransition(selection){
return {
selection: function() { return selection; }
}
}

tape("selection.join(enter, update, exit) allows callbacks to return a transition", function(test) {
var document = jsdom("<p>1</p><p>2</p>"),
p = d3.select(document.body).selectAll("p").datum(function() { return this.textContent; });
p = p.data([1, 3], d => d).join(
enter => mockTransition(enter.append("p").attr("class", "enter").text(d => d)),
update => mockTransition(update.attr("class", "update")),
exit => mockTransition(exit.attr("class", "exit"))
);
test.equal(document.body.innerHTML, "<p class=\"update\">1</p><p class=\"exit\">2</p><p class=\"enter\">3</p>");
test.end();
});

0 comments on commit bb4da56

Please sign in to comment.