我有一个成员-cli 2.4.2应用程序,它包含一个路由myroute和一个模板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}}`);
// ...
});发布于 2016-08-04 18:55:54
我认为最接近解决问题的方法是使用验收测试,在那里您可以使用jQuery,也可以导航到应用程序中的某些路线。您还可以在那里获得异步助手,如andThen、visit。请参考Ember验收测试指南。
https://stackoverflow.com/questions/38774379
复制相似问题