Ember.js 测试";“装载”;在余烬验收测试中的状态
在验收测试中,我想确认“加载指示器”在异步操作期间是否正确显示和隐藏。假设我有一个动作,看起来像这样:Ember.js 测试";“装载”;在余烬验收测试中的状态,ember.js,ember-cli,Ember.js,Ember Cli,在验收测试中,我想确认“加载指示器”在异步操作期间是否正确显示和隐藏。假设我有一个动作,看起来像这样: myAction() { this.set('isLoading', true); someAsyncMethod().then(answer => { this.set('isLoading', false); }); } <button class="my-button" {{action "myAction"}}> {{#i
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>
以及一个如下所示的模板:
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.
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
});
});