2017-02-23 1 views
1

Dans mon test d'acceptation, je souhaite confirmer que l'indicateur de chargement est correctement affiché et masqué pendant une action asynchrone. Disons que j'ai une action qui ressemble à ceci:Test de l'état de "chargement" dans un test d'acceptation Ember

myAction() { 
    this.set('isLoading', true); 
    someAsyncMethod().then(answer => { 
     this.set('isLoading', false); 
    }); 
} 

Et un modèle qui ressemble à ceci:

<button class="my-button" {{action "myAction"}}> 
    {{#if isLoading}} 
    <i class="loader"></i> 
    {{/if}} 
    Click me ! 
</button> 

Et enfin, le test:

test('My super action', function(assert) { 
    visit('/my-route'); 
    andThen(() => { 
     click('.my-button'); 
     // Here, since the click() helper is async, the action isn't 
     // called, so the loader isn't shown yet. 
    }); 
    andThen(() => { 
     // Here, the load is finished, so the loader is removed 
    }); 
}); 

Ma question est la suivante: Où puis-je faire l'affirmation que le chargeur est montré?

Répondre

0
test('My super action', function(assert) { 
    visit('/my-route'); 
    andThen(() => { 
     click('.my-button'); 
     // Here, since the click() helper is async, the action isn't 
     // called, so the loader isn't shown yet. 
     Ember.run.next(function() { 
     //here is fine, as we are in the next run loop the promise returned in the action has started loading 
     }); 
    }); 
    andThen(() => { 
    // Here, the load is finished, so the loader is removed 
    }); 
});