1

In our mocha-phantomjs unit tests for our ember application, I'm adding some event listeners to a video element in the DOM:

didInsertElement: function() {
  this._super();
  var video = this.$('.video-review').get(0);
  var self = this;
  video.addEventListener('error', function(err){
    self.set('isReviewEnabled', false);
    console.error(video.error);
  }, false);
},

Now I need to test the video element throwing an error and assert the graceful degradation code executes properly:

test("add video", function(done) {
  Ember.run(function() {
    widget.setFile({type: 'video/mp4', size: 100000});
    // should cause video element to throw error
  });
  // app gracefully degrades and is able to upload without .video-review
  findWithAssert('.alert-upload-ready')

All of my ember code executes as expected, except for the DOM video element event listener which never fires. The graceful degradation depends on this event listener firing. So I guess my question boils down to this: ?

How do I force/simulate DOM element events in an ember mocha-phantomjs test?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Robert Carter Mills
  • 793
  • 1
  • 9
  • 19

0 Answers0