Ember 2,验收测试,websocket挂起和挂起()等待待完成

时间:2017-09-02 15:06:45

标签: sockets ember.js websocket ember-cli acceptance-testing

我在“验收测试我的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(如果我打开) Chrome还有一个挂起的websocket调用...)。

如果我从 index.hbs 中删除此组件,一切都按预期工作。

登录后,我应该告诉andThen()帮助者忽略持续处于待定状态的service('notifications')的待处理状态?

怎么办?

1 个答案:

答案 0 :(得分:0)

对我来说,我面对的是因为我使用的一种轮询方法是在几秒钟内调用我的服务器来获取内容。我所做的是在测试模式下运行时禁用该代码

if(!Ember.testing){
  //polling
}

AndThen()基本上等待你的所有承诺在执行之前解决。