2017-02-23 18 views
1

受理テストでは、非同期処理中に「ローディングインジケータ」が正しく表示され、非表示になっていることを確認します。のは、私はこのようになりますアクションを持っているとしましょう:Ember受入れテストで「ローディング」状態をテストします

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

そして、このようになりますテンプレート:

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

そして最後に、テスト:

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 
    }); 
}); 

私の質問は次のとおりです。ローダーが表示されているという主張はどこで行うことができますか?

答えて

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 
    }); 
}); 
関連する問題