如何将emberjs mocha-phantomjs测试与dom事件监听器集成

时间:2015-04-13 23:48:43

标签: ember.js javascript-events ember-testing mocha-phantomjs

在我们的ember应用程序的mocha-phantomjs单元测试中,我将一些事件监听器添加到DOM中的video元素:

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);
},

现在我需要测试video元素抛出错误并断言优雅降级代码正确执行:

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')

我的所有余烬代码都按预期执行,但从不触发的DOM视频元素事件监听器除外。优雅的降级取决于此事件侦听器触发。所以我想我的问题归结为:?

如何在ember mocha-phantomjs测试中强制/模拟DOM元素事件?

0 个答案:

没有答案