私は自分の ember アプリケーションの統合テストを行っていますが、テストの実行後にプロミスが解決されるため、テストの 1 つが失敗しています。私の約束は、アニメーション イベント (bs 崩壊) をラップします。ここに私がテストしようとしているコードの一部があります:
//in my component
/**
* Closes the component DOM with collapse animation
*
* @method 'animateClose'
* @return {Ember.RSVP.Promise} promise that gets resolved once the collapse animation is complete
*/
animateClose() {
let element = Ember.$(this.get('element'));
return new Ember.RSVP.Promise(function(resolve) {
element.on('hidden.bs.collapse', function() {
resolve();//never gets here!!!
});
element.collapse('hide');
});
},
actions: {
/**
* Invokes close action.
*
* @action 'close'
* */
close() {
let defer = Ember.RSVP.defer();
defer.promise.then(function() {
return this.animateClose().then(function() {
this.sendAction("close");
}.bind(this));
}.bind(this));
this.sendAction("confirmClose", defer);
}
}
ご覧のとおり、遅延オブジェクトをコントローラーに渡しています。コントローラーは、いくつかの基準に基づいて解決し、遅延オブジェクトが解決されると、コンポーネントで折りたたみアニメーションを実行して閉じます。私のテストコードは次のようになります。
test("should save and close", function(assert) {
click(".save-close-btn");//this invokes the close action in component
//wait();
andThen(function() {
//assert something
});
});
デバッグすると、アサーションが最初にヒットし、その後 animateClose から返されたプロミスが解決され、テストが失敗することがわかります。この問題を解決するにはどうすればよいですか? ありがとう。
更新:私のコンポーネントが何らかの理由で完全に折りたたまれていないことが判明したため、「animateClose」内の解決が起動されていません。崩壊イベントが完了せず、dom が「崩壊」状態にある理由がわからない
一時的な解決策:今のところ、ブートストラップの折りたたみをダンプし、代わりに jquery スライド アニメーションを使用しました。テストは正常に機能しています。ブートストラップ折りたたみアニメーション/イベントを台無しにするテスト環境で何かが起こっているに違いありません。