首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在编写QUnit集成测试时,如何处理`Ember.Application.initializer`发出的asyc请求?

在编写QUnit集成测试时,如何处理`Ember.Application.initializer`发出的asyc请求?
EN

Stack Overflow用户
提问于 2013-08-31 09:35:26
回答 1查看 341关注 0票数 2

我正在尝试用QUnit设置ember.js来编写集成测试。

遵循我在http://emberjs.com/guides/testing/integration/上的指导:

代码语言:javascript
复制
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时,我得到以下错误:

代码语言:javascript
复制
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包装一些东西,但我不知道是什么。

EN

回答 1

Stack Overflow用户

发布于 2013-11-19 21:57:13

理想情况下,您的单元和集成测试应该独立于外部资源(如HTTP API)运行,因此mocking HTTP requests is the easiest pattern

要获得真正的全栈烟雾测试,您需要使用PhantomJS等浏览器自动化工具来测试该应用程序。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18543623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档