# Integration tests ignoring promises executed in controller action

**URL:** <https://discuss.emberjs.com/t/integration-tests-ignoring-promises-executed-in-controller-action/6835>\
**Category:** Testing\
**Created:** [December 3, 2014, 9:13pm UTC](https://discuss.emberjs.com/t/integration-tests-ignoring-promises-executed-in-controller-action/6835 "2014-12-03T21:13:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![house9](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/house9/32/9531_2.png) [@house9](https://discuss.emberjs.com/u/house9)\
**Post date:** [December 3, 2014, 9:13pm UTC](https://discuss.emberjs.com/t/integration-tests-ignoring-promises-executed-in-controller-action/6835/1 "2014-12-03T21:13:41Z")

</div>

I am having some issues with integration tests completing and not waiting for promises on the model to complete. (NOTE: using ember-cli stock setup)

The test code:

```auto
test 'Saving a projects bid', ->
  visit('/projects/1').then ->
    fillIn('.rate', '10.00')
    click('.save')
    andThen ->
      equal(find('.save').is(':visible'), false)

```

The controller

```auto
ProjectBidNewController = Ember.ObjectController.extend
  rate: null
  rateBinding: 'rate'
  actions:
    save: ->
      project = @get('model')

      bid = @store.createRecord 'project-bid',
        rate: @get('rate')
        project: project

      project.get('project_bids').then (bids) ->
        debugger # <-- never gets here when integration test is running
        bids.pushObject bid
        bid.save().then ->
          # hide the button

```

Note in the controller save action there are two nested promises, the first one never runs during the integration test, works just fine in the browser.

Maybe I am doing something wrong? After some googling I came across [this stackoverflow post](http://stackoverflow.com/questions/26498845/using-ember-cli-how-do-i-get-an-acceptance-test-to-wait-for-a-promise) which suggests “_andThen will only wait for promises created using Ember Test promises_”, if I read that correctly - my model promises in the controller action are being executed outside of ‘Ember Test promises’ and so the test will not wait for them to complete.

Feeling a little lost, it seems like this should ‘just work’? Any pointers in the right direction would be appreciated.

---

<div class="post-metadata">

**Author:** ![stefan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/stefan/32/14174_2.png) [@stefan](https://discuss.emberjs.com/u/stefan)\
**Post date:** [December 4, 2014, 2:16pm UTC](https://discuss.emberjs.com/t/integration-tests-ignoring-promises-executed-in-controller-action/6835/2 "2014-12-04T14:16:39Z")

</div>

you should open this as a bug. Not that i think the current behaviour is a bug, but because it is entirely non-obvious how to handle these situations.

---

<div class="post-metadata">

**Author:** ![ivogt](https://avatars.discourse-cdn.com/v4/letter/i/96bed5/32.png) [@ivogt](https://discuss.emberjs.com/u/ivogt)\
**Post date:** [December 7, 2014, 12:47am UTC](https://discuss.emberjs.com/t/integration-tests-ignoring-promises-executed-in-controller-action/6835/3 "2014-12-07T00:47:30Z")

</div>

I think you should be wrapping your test into Ember.run as in my example below. Not sure why you are not getting warning about it during test runs.

```
test("Account", function() {
  stop();
   Ember.run(function(){
     store.find('account','this').then(function(account){
      start();
      ok(account,"Found account!");
    }, function(err){
      start();
      ok(false, "Account request is rejected, error:" + (err.stack || err.message) );
    });
  });
});

```
