diff --git a/test/core/transition-test-attr.js b/test/core/transition-test-attr.js index 49743e0c..5fe62433 100644 --- a/test/core/transition-test-attr.js +++ b/test/core/transition-test-attr.js @@ -5,16 +5,29 @@ var assert = require("assert"); module.exports = { topic: function() { - var callback = this.callback, - div = d3.select("body").append("div"); + var cb = this.callback; - div + var s = d3.select("body").append("div") .attr("width", 20) - .transition() + .attr("color", "red"); + + var t = s.transition() + .attr("width", 100) .attr("width", 200) - .each("end", function() { callback(null, div); }); + .attr("color", function() { return "green"; }) + .each("end", function() { cb(null, {selection: s, transition: t}); }); }, - "sets an attribute as a number": function(div) { - assert.equal(div.attr("width"), "200"); + "defines the corresponding attr tween": function(result) { + assert.typeOf(result.transition.tween("attr.width"), "function"); + assert.typeOf(result.transition.tween("attr.color"), "function"); + }, + "the last attr operator takes precedence": function(result) { + assert.equal(result.selection.attr("width"), "200"); + }, + "sets an attribute as a number": function(result) { + assert.equal(result.selection.attr("width"), "200"); + }, + "sets an attribute as a function": function(result) { + assert.equal(result.selection.attr("color"), "rgb(0,128,0)"); } }; diff --git a/test/core/transition-test-style.js b/test/core/transition-test-style.js index 15f70b9e..39eb426b 100644 --- a/test/core/transition-test-style.js +++ b/test/core/transition-test-style.js @@ -14,7 +14,7 @@ module.exports = { var t = s.transition() .style("background-color", "green") .style("background-color", "red") - .style("color", "green", "important") + .style("color", function() { return "green"; }, "important") .each("end", function() { cb(null, {selection: s, transition: t}); }); }, "defines the corresponding style tween": function(result) { @@ -25,6 +25,9 @@ module.exports = { assert.equal(result.selection.style("background-color"), "rgb(255,0,0)"); }, "sets a property as a string": function(result) { + assert.equal(result.selection.style("background-color"), "rgb(255,0,0)"); + }, + "sets a property as a function": function(result) { assert.equal(result.selection.style("color"), "rgb(0,128,0)"); }, "observes the specified priority": function(result) { diff --git a/test/core/transition-test-styleTween.js b/test/core/transition-test-styleTween.js index ac2aae5b..a10781aa 100644 --- a/test/core/transition-test-styleTween.js +++ b/test/core/transition-test-styleTween.js @@ -9,7 +9,8 @@ module.exports = { dd = [], ii = [], tt = [], - vv = []; + vv = [], + fails = 0; var s = d3.select("body").append("div").selectAll("div") .data(["red", "green"]) @@ -17,6 +18,7 @@ module.exports = { .style("background-color", function(d) { return d3.rgb(d)+""; }); var t = s.transition() + .styleTween("background-color", function() { ++fails; }) .styleTween("background-color", tween); function tween(d, i, v) { @@ -29,7 +31,8 @@ module.exports = { data: dd, index: ii, value: vv, - context: tt + context: tt, + fails: fails }); return i && d3.interpolateHsl(v, "blue"); } @@ -44,6 +47,9 @@ module.exports = { "defines the corresponding style tween": function(result) { assert.typeOf(result.transition.tween("style.background-color"), "function"); }, + "the last style tween takes precedence": function(result) { + assert.equal(result.fails, 0); + }, "invokes the tween function": function(result) { assert.deepEqual(result.data, ["red", "green"], "expected data, got {actual}"); assert.deepEqual(result.index, [0, 1], "expected data, got {actual}");