vendredi 11 août 2017

how to mock import in Ember sinon

I am writing unit test for the following method in an Ember component:

setupDragAndDrop: function (component) {
Ember.$('.draggable').draggable({ revert: true, revertDuration: 1000, stack: '.draggable' });
Ember.$('.droppable').droppable({
  hoverClass: component.hoverClass ? component.hoverClass : 'hover-highlight',
  drop: function (event, ui) {
    if (Ember.getWithDefault(component, 'swapOnUI', false)) {
      component.swapNodes(Ember.$(this).get(0), Ember.$(ui.draggable).get(0));
    }
  }
});

if (get(this, 'droppable')) {
  this.$().on('drop', function () {
    component.sendAction('dropped', { destination: get(component, 'idTag'), type: get(component, 'type') });
  });
}

if (get(this, 'draggable')) {
  this.$().on('dragstart', function () {
    component.sendAction('dragged', { source: get(component, 'idTag'), type: get(component, 'type') });
  });
}
}

As you see, it calls Ember.$('.draggable'). Now how do I stub this Ember.$ from my tests such that I can check if draggable, droppable are called?




Aucun commentaire:

Enregistrer un commentaire