lundi 14 décembre 2015

Trigger custom event in Ember component integration test

Lets say I add two custom events for paste and cut in app.js

App = Ember.Application.extend({
  customEvents: {
    cut: 'cut',
    paste: 'paste'
  },
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver: Resolver,
  LOG_TRANSITIONS: true
});

My component then has something like

export default Ember.Component.extend({
  cut: function(event) {
    Ember.run.next(this, () => {
      this.send('keyDownAction', null, event);
      this.send('keyUpAction', null, event);
    });
  },
  paste: function(event) {
    Ember.run.next(this, () => {
      this.send('keyDownAction', null, event);
      this.send('keyUpAction', null, event);
     });
  }
});

My component has an {{input}} amongst other things. When writing an integration test for the component none of the above will trigger the paste:

this.$('input').val('pear').trigger('paste');

this.$('input').val('pear');
this.$().trigger('paste');

this.paste();

How do I trigger a custom event in a component integration test?

These fire absolutely fine in the actual application when the user pastes via either ctrl + v or right click + paste.




Aucun commentaire:

Enregistrer un commentaire