[英]Integration test a routes template in Ember.js
我有一個ember-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}}`);
// ...
});
我認為,解決該問題最接近的方法是使用驗收測試,在其中可以使用jQuery並導航到應用程序中的某些路由。 您還會在那里獲得異步幫助者,例如andThen
,然后visit
。 請參閱Ember驗收測試指南 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.