【发布时间】:2015-12-17 09:10:19
【问题描述】:
我在接受测试使用 ic-ajax 提交表单的 Ember CLI 组件时遇到问题。
问题是验收测试中的andThen函数没有等待表单提交解决。
组件:
import Ember from 'ember';
import ajax from 'ic-ajax';
export default Ember.Component.extend({
tagName: 'form',
// ...snip...
submit(e) {
e.preventDefault();
const request = ajax({
url: "url.com"
});
// Debugging in test mode, Ember.Test.lastPromise === null here?
}
// ...snip...
});
验收测试:
test('it surfaces errors', function(assert) {
visit('/test');
let component;
andThen(function() {
component = find('.my-form');
fillIn('input[Placeholder="Email"]', 'not@valid');
click('button[type="submit"]');
andThen(function() {
// PROBLEM: This code doesn't wait for the ic-ajax promise to resolve
assert.ok(component.hasClass('error'), "The component applied the error classname.");
});
});
});
创建ic-ajax 承诺似乎没有设置Ember.Test.lastPromise,这意味着andThen 不会等待表单提交返回。
我错过了什么吗?
【问题讨论】:
标签: javascript ajax ember.js