我是第一次在验收测试我的Ember应用程序时开始。
因此,我从登录开始,它是这样的:
测试/接受/登录-test.js:
import { test } from "qunit";
import moduleForAcceptance from "myapp/tests/helpers/module-for-acceptance";
moduleForAcceptance("Acceptance | login");
test("Should login", function(assert) {
visit("/login");
fillIn("input[type=email]", "user@email.com");
fillIn("input[type=password]", "userpass");
click("button[type=submit]");
andThen(() => {
assert.equal(currentURL(), "/");
assert.equal(find("h1").text(), "Hello!");
});
});
它的永远不会在
andThen()
中变成,因此它卡在click("button[type=submit]");
上。我明白为什么。
在我的app/templates/index.hbs中,我有一个组件通知,它依赖于一个Websocket,该Websocket在我的单页应用程序中一直处于挂起状态(如果我打开Chrome,则有一个挂起的Websocket调用...)。
如果我从index.hbs中删除此组件,那么一切都会按预期进行。
登录后,我应该告诉
andThen()
帮助程序忽略一直处于未决状态的service('notifications')
的未决状态?怎么办?
最佳答案
对我来说,我面对这种情况是因为我使用了一种轮询方法,该方法在几秒钟内调用服务器以获取某些内容。我所做的是在测试模式下运行时禁用了该代码
if(!Ember.testing){
//polling
}
AndThen()基本上在执行之前等待所有 promise 得到解决。
关于sockets - Ember 2,验收测试,Websocket挂起,然后Then()等待挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46015141/