Asynchronous call when testing ember

In my ember application, I use bootbox ( http://bootboxjs.com/ ) to confirm the removal of some models. In my qunit test, I press the button with {{action}}, in this action I open the boot box. In the text, I click OK on the boot box.

But the andThen method does not wait for the boot box to disappear. Therefore, checking if a model is deleted is always false. I tried to return a promise, but the assistant andThen also did not wait for promises.

Is there a way that allows testing to wait until the bootbox promise is resolved or the boot box callback is completed?

Additional information: My template:

    <button class="btn btn-default" {{action 'askDelete' target="view"}} data-toggle="tooltip" data-placement="right" {{translateAttr title="trips.remove"}}><i class="fa fa-trash-o"></i></button>

My view:

actions: {
    askDelete: function(){
        var self = this;
        self.$('td').slideUp('500').promise().then(function(){
            self.get('controller').send('delete');
        });
    }
}

My controller:

actions: {
    save: function(){
                self.get('content').save().then(function(){
                self.get('controllers.history').transitionToPrevious('trips.index');
            });

My test:

click(".specific-row .action-buttons button");

andThen(function() {
    // Check if the row is indeed removed from the table
    ok(find(".content-row table tr:contains('content-of-row')").length === 0, "deleted and removed from the table");
});

ok , , false.

jsfiddle : http://jsfiddle.net/21af9puz/1/

+4
1

, , ember. - :

test('Test ', function(){
    console.log(find('#link'));
  visit('/');
  andThen(function() {
      equal(find('#block').length,1, 'There should be a block on the page');
      click("#link"); 

      stop();
      Em.run.later(function(){
        start();
        $('.btn.btn-primary').click();
        equal(find('#block').length,0, 'There should be no block on the page');
      }, 1000);


  });
});

http://jsfiddle.net/xke7851k/

+5

All Articles