1

簡単な統合テストを実行しようとしています。ember-cli Web サイトの統合例から始めました。現在、ブラウザー (localhost:4200/tests) でテストすると、次のケースは期待どおりの場所にルーティングされますが、ハングするだけで、成功も失敗もありません。

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

    });
});

ここで私が間違っていることはありますか?または、それを行う別の方法はありますか?

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';

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-exampleにあります。run.later を削除すると、テストはパスします。

4

1 に答える 1

2

この問題を解決してくれた freenode の #emberjs チャンネルの teddyz に感謝します。問題は、非同期ヘルパーが が終了visit()するのを待つことですEmber.run.later()が、これを構造化した方法では、終了する前に別のrun.later. したがって、訪問は基本的に永遠に待ちます。解決策は、setTimeout とEmber.run. コードは以下です。

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 フォーラム ( http://discuss.emberjs.com/t/proper-way-to-handler-timers-w-ember-testing/4693/8 )globalSettingsでの議論に従ってオブジェクトを作成しました。タイマーとテストを処理する方法。これにより、テスト中にタイムアウトを調整できます (つまり、機能をテストするためにタイムアウトを非常に低く設定し、テストの実行速度を維持します)。

于 2015-01-11T13:49:10.990 に答える