且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ember / emberfire运行循环验收测试

更新时间:2023-09-17 21:04:40

这听起来像你的问题可能与我看到的错误



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.