Sunday, November 4, 2018

Unit testing D3 transitions

Hello everyone,

Today I am going to tell you about unit testing D3 transitions. Anyone working in Javascript technology would be very much aware with D3.js library. D3.js is a data driven javascript library for Dom manipulating, which comes with a large set of advanced features, enabling the quick calculation and rendering of very large data sets.


Recently I was working on creating charts using D3.js library and as the client demanded the chart needed to be fancied with some good animations.

First of all, creating transitions in D3 charts require a lot of skill for everything to fall in place and then writing unit tests for that is SOMETHING. (FYI, I am pretty new to D3.js library. Started working on them just a month back).

Chart code:

I am referencing to this d3 bar chart to write unit tests:

http://bl.ocks.org/enjalot/1429426


Unit tests:

function flushAllD3Transitions() {
    var now = performance.now;
    performance.now = function() { return Infinity; };
    d3.timerFlush();
    performance.now = now;
 }

Thank you for taking the time to read this. I hope this would have helped. 

P.S. If you want me to discuss any other topic, write to me in the comments below.

No comments:

Post a Comment