[英]Integration test a routes template in Ember.js
I have an ember-cli 2.4.2 application that contains a route myroute
and a template myroute.hbs
. 我有一个ember-cli 2.4.2应用程序,其中包含路线
myroute
和模板myroute.hbs
。
When I integration test components, I do something like this, 当我集成测试组件时,我会做类似的事情,
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');
});
When I use moduleFor('route:myroute')
, the call this.render()
throws this.render is not a function
. 当我使用
moduleFor('route:myroute')
,调用this.render()
抛出this.render is not a function
。 As below, if I call route.render()
it throws Error: Assertion Failed: Could not find "hbs{{myroute}}" template, view, or component.
如下所示,如果我调用
route.render()
则会引发Error: Assertion Failed: Could not find "hbs{{myroute}}" template, view, or component.
The goal is to integration test a route's template. 目的是集成测试路线模板。 I'd like to use jQuery to ensure the template rendered correctly.
我想使用jQuery来确保模板正确呈现。 I have some computed properties on the route that influence what's displayed.
我在路线上有一些计算出的属性会影响显示的内容。
I can't seem to find any good documentation on integration testing a routes template. 我似乎找不到关于集成测试路由模板的任何好的文档。 Any ideas or pointers?
有什么想法或建议吗? Many thanks.
非常感谢。
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}}`);
// ...
});
If you need to test template of a route, use acceptance tests . 如果需要测试路径模板,请使用验收测试 。
If you need to test methods and computed properties of a route, use unit tests . 如果需要测试路线的方法和计算属性,请使用单元测试 。
I think the closest you can get to solve the problem is to use acceptance tests where you can use jQuery and also navigate to certain routes in your application. 我认为,解决该问题最接近的方法是使用验收测试,在其中可以使用jQuery并导航到应用程序中的某些路由。 You also get async helpers there like
andThen
, visit
. 您还会在那里获得异步帮助者,例如
andThen
,然后visit
。 Please refer to Ember Guides on Acceptance Testing . 请参阅Ember验收测试指南 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.