title: Ember.js Testing async action in controller
body: <p>I've a controller with an action that invoke a method that do some async stuff and return a promise.</p>
  
  <pre><code>export default Ember.Controller.extend({
  
    _upload: function() {
      // return a promise
    },
    actions: {
      save: function(item) {
        this._upload(item).then(function(response) {
          // Handle success
        }, function(error) {
          // Handle error
        }
      }
    }
  });
  </code></pre>
  
  <p>I would like to unit test the code under <code>Handle success</code> and <code>Handle error</code>.
  In my unit test I've mocked the <code>_uploadMethod</code> using </p>
  
  <pre><code>controller.set("_upload", function() {
    return new Ember.RSVP.Promise(function(resolve) {
      resolve({name: "image1"});
    });
  });
  </code></pre>
  
  <p>And then I invoke the action and assert that the success handler has done is job</p>
  
  <pre><code>controller.send("save", "item");
  assert.equal(controller.get("selected.item"), "item");
  </code></pre>
  
  <p>The problem is that the assertion fails because it's run before the promise is resolved and all the stuff in success handler is completed.</p>
  
  <p>How can I wait the promise to resolve before the assertion is checked?</p>