我正在尝试让一些测试通过ember 插件。它工作正常,直到昨天我添加了一些稍后在运行循环中使用 Em.run.next 运行的代码。
这是我在测试中所做的。
visit('/').then(function() {
find('bm-select').click();
andThen(function() {
equal(1,1, 'yay');
});
});
问题是当点击被触发时,后面的函数在andThen
. 到那时我所有的测试都完成了,它会抛出错误。我的印象是,然后应该等待所有异步内容完成。
这就是触发点击时我的代码的样子(点击时触发focusOut事件)
lostFocus: function() {
if(this.get('isOpen')) {
Em.run.later(this, function() {
var focussedElement = document.activeElement;
var isFocussedOut =
this.$().has(focussedElement).length === 0 && !this.$().is(focussedElement);
if(isFocussedOut) {
this.closeOptions({focus:false});
}
}, 0);
}
}.on('focusOut'),
你可以看到它给出了一个错误Uncaught TypeError: Cannot read property 'has' of undefined
。这是来自 focusOut 方法。到函数执行时,组件 _state 正在“销毁”并this.$()
返回未定义。
我尝试了wait
帮助程序,但仍然无法使测试正常工作。这通常是怎么做的。我已提取测试以在 bin 中运行。这是它的链接。