Unit testing async functions in Ember controllers
<p>I've hit a very weird problem: I'm trying to make unit tests to achieve 100% testing coverage on my application. 
And of course I wrote some tests for my controllers but it seems like there is no way to test anything async in Ember (2.4.0) using ember-cli.  </p>

<ol>
<li><p>I have a function in controller that does this: </p>

<pre><code>readObject() {
   this.store.findRecord('myModel',1).then(function(obj) {
      this.set('property1',obj.get('property2');
   }.bind(this));
}
</code></pre></li>
<li><p>I'm writing a test that should cover this function.</p>

<pre><code>test('action readObject', function (assert) {
   const cont = this.subject();
   cont.readObject();
   assert.equal(cont.get('property1'), 'someValue);
});
</code></pre></li>
<li><p>Obivously, this assert wouldn't work because readObject() is async call but this isn't the root of the problem.   The problem is that then a callback in this.store.findRecord is being executed - my controller <strong>is already destroyed</strong>!  So I get "calling set on destroyed object" error there.</p></li>
</ol>

<p>In other words - even if I wrap my function in a promise and reformat both functions like this:</p>

<pre><code>readObject() {
   return new Promise(function(resolve) {
       this.store.findRecord('myModel',1).then(function(obj) {
          this.set('property1',obj.get('property2');
          resolve();
       }.bind(this));
   }.bind(this));
}
</code></pre>

<p>and </p>

<pre><code>test('action readObject', function (assert) {
  const cont = this.subject();
  cont.readObject().then(function() {
      assert.equal(cont.get('property1'), 'someValue);
  });
});
</code></pre>

<p>It wouldn't work, because after executing readObject() my controllers become immediately destroyed, not waiting for any callbacks. 
So, it could be any async call instead of store.findRecord - it could be Ember.run.later, for example. </p>

<p>Does anybody had the same issue? I've read a lot of articles  I can't believe that Ember with such a big community doesn't provide a way to make async unit tests.</p>

<p>If anyone has any clues - please give me a hint, cause I'm kinda lost here. At the moment I have two thoughts:</p>

<ol>
<li><p>I'm making controllers wrong, Ember doesn't suppose any async operations inside of it.  But even if I move async calls to services - I hit the same problem with writing unit tests for them. </p></li>
<li><p>I have to decompose my functions to  </p>

<pre><code>readObject() {
  this.store.findRecord('myModel',1).then(this.actualReadObject.bind(this));
}

actualReadObject(obj) {
   this.set('property1',obj.get('property2');
}
</code></pre></li>
</ol>

<p>to have at least callbacks body covered with tests, but this means I never get 100% testing coverage in my app.  </p>

<p>Thank you in advance for any clues. :)</p>