我正在尝试用QUnit设置ember.js来编写集成测试。
遵循我在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包装一些东西,但我不知道是什么。
发布于 2013-11-19 21:57:13
理想情况下,您的单元和集成测试应该独立于外部资源(如HTTP API)运行,因此mocking HTTP requests is the easiest pattern。
要获得真正的全栈烟雾测试,您需要使用PhantomJS等浏览器自动化工具来测试该应用程序。
https://stackoverflow.com/questions/18543623
复制相似问题