2

myrouterouteと templateを含む ember-cli 2.4.2 アプリケーションがありますmyroute.hbs

コンポーネントを統合するときは、次のようにします。

import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('mycomponent', 'Integration | Component | mycomponent', {
    integration: true
});

test('the component', function(assert) {
    this.render(hbs`
        {{#mycomponent}}
            text
        {{/mycomponent}}
    `);

    assert.notEqual(this.$('.container').text().trim(), 'text');
});

を使用するmoduleFor('route:myroute')と、呼び出しthis.render()がスローされthis.render is not a functionます。route.render()以下のように、スローと呼ぶとError: Assertion Failed: Could not find "hbs{{myroute}}" template, view, or component.

目標は、ルートのテンプレートを統合テストすることです。テンプレートが正しくレンダリングされるように jQuery を使用したいと思います。表示される内容に影響を与える計算されたプロパティがルートにいくつかあります。

ルート テンプレートの統合テストに関する適切なドキュメントが見つからないようです。アイデアや指針はありますか?どうもありがとう。

import Ember from 'ember';
import { moduleFor, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleFor('route:myroute', 'Integration | Route | myroute', {
    integration: true,
});

test('the route', function(assert) {
    const mockModel = {
        response: { field1: true, field2: false }
    };

    const route = this.subject({ model: mockModel });

    route.render(`hbs{{myroute}}`);

    // ...
});
4

2 に答える 2

3

ルートのテンプレートをテストする必要がある場合は、受け入れテストを使用します。

ルートのメソッドと計算されたプロパティをテストする必要がある場合は、ユニット テストを使用します。

于 2016-08-04T20:19:23.057 に答える