Ember集成测试在访问路由后挂起 [英] Ember integration testing hangs after visiting route

查看:157
本文介绍了Ember集成测试在访问路由后挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一个简单的集成测试,我从ember-cli网站上的集成示例开始。现在当我在浏览器中测试(localhost:4200 / tests)时,以下情况会路由到我所期望的位置,但是它只是挂起,从未成功或失败。



<从ember导入Ember pre>
import'test'from'ember-qunit';
从'../helpers/start-app'导入startApp;
var App;

module('Integration - Create Event',{
setup:function(){
App = startApp();
},
teardown: function(){
Ember.run(App,App.destroy);
}
});

test('check customers',function(){
visit('/ new');
andThen(function(){
fillIn('input#标题','事件名称');
ok(true);
//等于(find('。customers input [type =checkbox]')长度,6,'客户复选框显示');

});
});

我在这里做错了吗?还是有不同的方法呢?



ember-cli 0.1.5和ember 1.9.1



编辑:

  ENV.APP.LOG_ACTIVE_GENERATION = true; 
ENV.APP.LOG_TRANSITIONS = true;
ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
ENV.APP.LOG_VIEW_LOOKUPS = true;

启用日志记录显示转换完成,但仍然无法解决或被拒绝。



编辑:



我想我缩小了。我有一个时钟服务,我正在注入所有的控制器,但是当我不注射它,我的测试通过。我需要时钟服务提供的功能,我如何仍然可以使用它,但让我的集成测试工作?

  // services / clock.js 
import Ember from'ember';

导出默认值Ember.Object.extend({
pulse:Ember.computed.oneWay('_ seconds')。readOnly(),
minutePulse:Ember.computed.oneWay '_ minutes')readOnly(),
tick:function(){
var clock = this;
Ember.run.later(function(){
var seconds = .get('_ seconds');
var minutes = clock.get('_ minutes');
if(typeof seconds ==='number'){
clock.set('_ seconds ',seconds + 1);
if(Math.floor((seconds + 1)/ 60)>分钟){
clock.set('_ minutes',minutes + 1);

}
},1000);
} .observes('_ seconds')。on('init'),
_seconds:0,
_minutes: 0
});

一个示例项目可以在 https://github.com/RyanHirsch/ember-test-example 。如果我删除run.later,测试将通过。

解决方案

感谢teddyz在freenode的#emberjs频道帮助我有这个问题。问题是async帮手 visit()等待 Ember.run.later()完成,但是我有这样的结构,在它完成之前触发另一个 run.later 。所以访问基本上等待着永远。该解决方案似乎是使用setTimeout与一个 Ember.run 。代码如下。

 从ember导入Ember; 

导出默认值Ember.Object.extend({
pulse:Ember.computed.oneWay('_ seconds')。readOnly(),
minutePulse:Ember.computed.oneWay '_minutes')readOnly(),
tick:function(){
var clock = this;
setTimeout(Ember.run.bind(clock,function(){
var seconds = this.get('_ seconds');
var minutes = this.get('_ minutes');
if(typeof seconds ==='number'){
this。 set('_ seconds',seconds + 1);
if(Math.floor((seconds + 1)/ 60)>分钟){
this.set('_ minutes',minutes + 1) ;
}
}
}),clock.get('globalSettings.timeout));
} .observes('_ seconds')。on('init'),
_seconds:0,
_minutes:0
});

我还创建了一个 globalSettings 对象根据关于ember论坛的讨论( http://discuss.emberjs.com/t/proper-way-to-handler-timers-w-ember-testing/4693/8 )关于处理计时器和测试的正确方法。这将允许在测试期间调整超时(即将其设置得非常低,以测试功能并仍然保持测试执行速度)


I am trying to do a simple integration test and I started from the integration example on the ember-cli website. Right now when I test in a browser (localhost:4200/tests), the follow case routes to where I expect, but then it just hangs and never does success or failure.

import Ember from "ember";
import { test } from 'ember-qunit';
import startApp from '../helpers/start-app';
var App;

module('Integration - Create Event', {
    setup: function() {
        App = startApp();
    },
    teardown: function() {
        Ember.run(App, App.destroy);
    }
});

test('check customers', function() {
    visit('/new');
    andThen(function() {
        fillIn('input#title', 'The Event Name');
        ok(true);
       // equal(find('.customers input[type="checkbox"]').length, 6, 'Customer checkboxes showing');

    });
});

Is there something I am doing wrong here? Or is there a different way to do it?

ember-cli 0.1.5 and ember 1.9.1

Edit:

    ENV.APP.LOG_ACTIVE_GENERATION = true;
    ENV.APP.LOG_TRANSITIONS = true;
    ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
    ENV.APP.LOG_VIEW_LOOKUPS = true;

Enabling logging shows that the transition completes, but andThen still never resolves or gets rejected.

Edit:

I think I've narrowed it down. I have a clock service that I am injecting into all controllers, but when I don't inject it at all, my test passes. I need the functionality the clock service provides, how can I still use it, but get my integration tests to work?

// services/clock.js
import Ember from 'ember';

export default Ember.Object.extend({
    pulse: Ember.computed.oneWay('_seconds').readOnly(),
    minutePulse: Ember.computed.oneWay('_minutes').readOnly(),
    tick: function () {
        var clock = this;
        Ember.run.later(function () {
            var seconds = clock.get('_seconds');
            var minutes = clock.get('_minutes');
            if (typeof seconds === 'number') {
                clock.set('_seconds', seconds + 1);
                if(Math.floor((seconds + 1) / 60) > minutes) {
                    clock.set('_minutes', minutes + 1);
                }
            }
        }, 1000);
    }.observes('_seconds').on('init'),
    _seconds: 0,
    _minutes: 0
});

An example project can be found at https://github.com/RyanHirsch/ember-test-example. If I remove the run.later the tests will pass.

解决方案

Thanks to teddyz in the #emberjs channel on freenode for helping me with this problem. The issue is that the async helper visit() waits for the Ember.run.later() to finish, but the way I have this structured, before it finishes it triggers another run.later. So the visit basically waits forever. The solution seems to be to use setTimeout with an Ember.run. Code is below.

import Ember from 'ember';

export default Ember.Object.extend({
    pulse: Ember.computed.oneWay('_seconds').readOnly(),
    minutePulse: Ember.computed.oneWay('_minutes').readOnly(),
    tick: function () {
        var clock = this;
        setTimeout(Ember.run.bind(clock, function () {
            var seconds = this.get('_seconds');
            var minutes = this.get('_minutes');
            if (typeof seconds === 'number') {
                this.set('_seconds', seconds + 1);
                if(Math.floor((seconds + 1) / 60) > minutes) {
                    this.set('_minutes', minutes + 1);
                }
            }
        }), clock.get('globalSettings.timeout'));
    }.observes('_seconds').on('init'),
    _seconds: 0,
    _minutes: 0
});

I've also created a globalSettings object per the discussion on the ember forums (http://discuss.emberjs.com/t/proper-way-to-handler-timers-w-ember-testing/4693/8) about the right way to handle timers and testing. This will allow for the adjusting of timeouts during testing (ie set them really low to test functionality and still maintain test execution speed)

这篇关于Ember集成测试在访问路由后挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆