Ember/emberfire run loop acceptance test

吃可爱长大的小学妹 提交于 2019-12-24 16:31:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/33088175/ember-emberfire-run-loop-acceptance-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!