lundi 1 février 2016

Ember: How can I ignore browser-triggered events in my Ember tests?

I have an Ember.Component that watches for mouseover events:

didInsertElement() {
  const guid = Ember.guidFor(this);
  this.$().on(`mouseover.${guid}`, this.handleMouseover.bind(this));
},

willDestroyElement() {
  const guid = Ember.guidFor(this);
  this.$().off(`mouseover.${guid}`);
},

handleMouseover() {
  this.run.scheduleOnce('afterRender', something);
}

Running acceptance tests on the command-line for this component works fine. The problem is that when I run them in an actual browser, it's easy to trigger real mouseover events. This causes the dreaded You have turned on testing mode, which disabled the run-loop's autorun. error.

Ideally, I'd like to change the component to something like

handleMouseover(event) {
  // in test env, only handle simulated events:
  if (env.environment === 'test' && !event.isSimulatedEvent) return;
  this.run.scheduleOnce('afterRender', something);
}

Aucun commentaire:

Enregistrer un commentaire