Ember / emberfire运行循环验收测试 [英] Ember/emberfire run loop acceptance test
问题描述
导出默认值Ember.Component.extend({
store:Ember.inject.service (),
didReceiveAttrs(){
this.handleSearchQueryChange();
},
/ **
*根据searchQuery
* /
handleSearchQueryChange(){
this.get('store')。query('animals',{
orderBy:'name',
startAt:this.attrs.searchQuery
})然后(searchResults => {
this.set('searchResults',searchResults);
});
}
});
我已经尝试过包裹 this.handleSearchQueryChange()
, this.get('store')。query ...
和 this.set('searchResults',searchResults)
在运行循环但仍然,验收测试只是不等待store.query完成。
有一件事要注意,这个商店查询执行在Live Firebase后端的请求。
我正在使用Pretender来嘲笑数据并解决这个问题。但是我也想通过Ember.run来解决它。任何人都提供解决方案?
这听起来像你的问题可能与我看到的错误
tl; dr
要解决此问题,我一直在使用定制测试服务员您可以使用安装ember install ember-cli-test-model-waiter
(对于Ember v2.0 +),它应该使您的测试工作没有任何进一步的设置(如果不是,请提交错误)。
更长的回答:
这个问题的根本原因是ember测试系统不知道如何处理Firebase的异步。对于大多数适配器,这不是问题,因为测试系统乐器AJAX调用和确保在继续之前已经完成,但这并不适用于Firebase的websockets通信。
一个href =https://github.com/gabrielgrant/ember-cli-test-model-waiter =nofollow noreferrer>我上面提到的自定义测试服务员通过等待所有型号解决之前的工作继续测试,所以应该使用任何非AJAX适配器。
So my acceptance test keeps on destroying itself before my promise finishes. I'm aware that I need to wrap my promise in Ember run loop but I just can't get it to work. Here's how my component looks:
export default Ember.Component.extend({
store: Ember.inject.service(),
didReceiveAttrs() {
this.handleSearchQueryChange();
},
/**
* Search based on the searchQuery
*/
handleSearchQueryChange() {
this.get('store').query('animals', {
orderBy: 'name',
startAt: this.attrs.searchQuery
}).then(searchResults => {
this.set('searchResults', searchResults);
});
}
});
I've already tried wrapping this.handleSearchQueryChange()
, this.get('store').query...
and this.set('searchResults', searchResults)
in a run loop but still, the acceptance test just doesn't wait for store.query to finish.
One thing to note that this store query performs a request on a live Firebase back-end.
I'm currently using Pretender to mock the data and solve this issue. But I'd like to solve it through Ember.run as well. Anyone care to provide a solution?
It sounds like your problem may have the same cause as the errors I've been seeing
tl;dr
To work around this issue, I've been using a custom test waiter. You can install it with ember install ember-cli-test-model-waiter
(for Ember v2.0+) and it should just make your test work without any further setup (if not, please file a bug).
Longer answer:
The root cause of this problem is that the ember testing system doesn't know how to handle Firebase's asynchronicity. With most adapters, this isn't a problem, because the testing system instruments AJAX calls and ensures they have completed before proceeding, but this doesn't work with Firebase's websockets communication.
The custom test waiter I mentioned above works by waiting for all models to resolve before proceeding with the test, and so should work with any non-AJAX adapter.
这篇关于Ember / emberfire运行循环验收测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!