Javascript unit tests

My team uses Jasmine and Karma to write unit tests for our javascript.

I have created a popup window very similar to the configuration popup for the Webix pivot grid.

I am trying to write a unit test that via jQuery drags an item from one list on the popup to another. I want to write unit tests for the functions that are triggered on these actions.

I’ve done this successfully in the past using the following jQuery

var $el = $(…item in source list…);
var fromPos = $el.offset();
var toPos = $(…destination list…).offset();
$el.trigger(jQuery.Event(“mousedown”, {which: 1, pageX: fromPos.left + 10, pageY: fromPos.top + 2}));
$el.trigger(jQuery.Event(“mousemove”, {which: 1, pageX: toPos.left + 10, pageY: toPos.top + 2}));
$el.trigger(jQuery.Event(“mouseup”, {which: 1, pageX: toPos.left + 10, pageY: toPos.top + 2}));

This doesn’t seem to cause anything to happen with the Webix controls. The onBeforeDropOut and OnBeforeDrag events I am trying to test are not triggered.

I know this is a long shot, but if anyone has any ideas how I could simulate drag and drop via javascript so I can unit test the window I build via Webix I would appreciate it.

  • mousedown ( target - element to drag )
  • mousemove ( any target )
  • mousemove ( target - element to drop )
  • mouseup ( any target )

A valid target for mousedown and mouseup events is vital.

Also, you can try to add webix.$testmode = true; it will make the library more tolerant to simulated events.