Since This algorithm is not final and it will probably be improved, I wanted to be able to test it. In fact, the plugin accepts a numeric row from deltaY as input and analyzes it. So for writing tests, nodejs and
travis-ci.org are enough to test commits.
To be able to test the plugin in nodejs, it is necessary that it can export itself in the commonjs format.
To do this, add verification and export of the constructor:
if (typeof exports === 'object') { module.exports = WheelIndicator; }
The input to the plug-in comes through an event object after the handler is created using addEventListener. Thus, in tests, we need to “lock” this method:
global.document = { addEventListener: function(type, handler){ currentDeltaArr.forEach(function(delta){ handler({ deltaY: delta }); }); } };
where delta is an array of test number series from deltaY. For convenient obtaining of such rows from various devices and OS we made a
test bench .
That's all, now it only remains to restore the plugin, create an instance and verify the data from the plugin with the reference.
Sample incoming data for test:
down: { moves: [ 'down' ], delta: [1,4,12,32,55,69,154,156,158,148,137,130,122,116,111,108,103,97,93,88,84,80,74,71,65,61,57,54,50,46,42,39,36,33,31,27,25,23,21,18,17,15,14,13,12,11,9,8,8,7,6,6,14,4,4,3,3,3,2,2,4,1,2,1,1,1,1,1,1,1,1,1,1], device: 'Mac OSX notebook trackpad' }