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

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

问题描述

我正在尝试做一个简单的集成测试,我从 ember-cli 网站上的集成示例开始.现在,当我在浏览器 (localhost:4200/tests) 中进行测试时,后续案例会路由到我期望的位置,但随后它就会挂起,永远不会成功或失败.

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 和 ember 1.9.1

ember-cli 0.1.5 and 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;

启用日志显示转换已完成,但 andThen 仍然永远不会解析或被拒绝.

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

我想我已经缩小了范围.我有一个时钟服务,我将它注入到所有控制器中,但是当我根本不注入它时,我的测试就通过了.我需要时钟服务提供的功能,我如何仍然使用它,但让我的集成测试工作?

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
});

可以在 https://github.com/RyanHirsch/ember-test 找到示例项目-例子.如果我删除 run.later 测试将通过.

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

推荐答案

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

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
});

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

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天全站免登陆