我想用QUnit来设置ember.js来编写集成测试。在编写QUnit集成测试时,如何处理'Ember.Application.initializer`中的asyc请求?
继http://emberjs.com/guides/testing/integration/的方向,我有:
document.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');
App.rootElement = '#ember-testing';
App.setupForTesting();
App.injectTestHelpers();
module("Integration Tests", {
setup: function() {
App.reset();
}
});
test("root lists first page of posts", function(){
visit("/").then(function() {
equal(find(".post").length, 5, "The first page should have 5 posts");
// Assuming we know that 5 posts display per page and that there are more than 5 posts
});
});
然而,当我运行QUnit我得到以下错误:
Assertion failed: You have turned on testing mode, which disabled the
run-loop's autorun. You will need to wrap any code with asynchronous
side-effects in an Ember.run
触发此断言错误,因为我想提出一个http请求应用程序初始化程序检查是否有当前的用户会话。如果没有有效的用户,这将返回401错误。 (如果我强制应用程序始终为此请求返回200,则不会发生此断言错误,并且测试会按预期继续)。
我相信应用程序和API通过返回一个无效用户的http错误正常运行,我不想为了让我的测试工作而更改为响应200。我需要做什么才能让ember和QUnit处理http错误和断言?从我读过的东西中,我需要用Ember.run
来包装一些东西,但我无法弄清楚什么。
你还有这个问题吗?也许我可以帮忙。 –
务必请帮助。对于我们这些也有这个问题的人来说,StackOverflow仍然很有帮助。所以,如果你知道答案,或有想法,请写出答案。我有这个问题,你的评论根本没有帮助。还在寻找... – Luc