1
votes

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

1 Answers

0
votes

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.