首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Ember.js中集成测试路由模板

在Ember.js中集成测试路由模板
EN

Stack Overflow用户
提问于 2016-08-04 18:01:45
回答 2查看 936关注 0票数 2

我有一个成员-cli 2.4.2应用程序,它包含一个路由myroute和一个模板myroute.hbs

当我集成测试组件时,我会这样做,

代码语言:javascript
复制
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来确保模板正确呈现。我在路由上有一些计算的属性,这些属性影响显示的内容。

我似乎找不到任何关于集成测试路由模板的好文档。有什么想法或建议吗?非常感谢。

代码语言:javascript
复制
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}}`);

    // ...
});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-08-04 18:55:54

我认为最接近解决问题的方法是使用验收测试,在那里您可以使用jQuery,也可以导航到应用程序中的某些路线。您还可以在那里获得异步助手,如andThenvisit。请参考Ember验收测试指南

票数 2
EN

Stack Overflow用户

发布于 2016-08-04 20:19:23

如果需要测试路由的模板,请使用验收试验

如果需要测试路由的方法和计算属性,请使用单元测试

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

https://stackoverflow.com/questions/38774379

复制
相关文章

相似问题

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