How to test a html5 drag and drop in qunit

backbone.js, html, javascript, jquery, qunit

Solution

If you set it a little different it makes a world of difference:

var event = new Event('drop',{
     stopPropagation: function() {return;}
});
event['originalEvent'] ={
    'dataTransfer':{
        'getData': function(){
            return 'tr#0.sprint'
        }
    }
};
$('tr#0.sprint').trigger(event);

This is a more 'manual' way of setting attributes of an javascript object. The arguments added to the constructor of the event are checked by the event object's construct.

Problem

I want to test a html 5 drag and drop what i though would work: From test file ``` var event = new Event('drop',{ 'originalEvent':{ 'dataTransfer':{ 'getData': function(){ return 'tr#0.sprint' } } }, stopPropagation': function() {return;} } $('tr#0.sprint').trigger(event); ``` This so that the event is triggered and all the functions are set to return what i want tested. actual script: Backbone framework ``` myView = Backbone.View.extend({ ... drop : function(event) { event.stopPropagation(); var data = event.originalEvent.dataTransfer.getData('element'); // some code }, ... }; ``` Sadly this error's to `Illigal function call` If i remove the `dataTransfer` object and try to set it myself i get a undefined error

Original source