ember-qunit如何在集成测试中渲染组件?

时间:2016-08-30 20:48:36

标签: ember.js ember-qunit ember-testing

这是ember-qunit的基本组件/集成测试。

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

moduleForComponent('my-component', 'TODO: put something here', {
  integration: true
});

test('it renders', function(assert) {
  this.render(hbs`{{my-component}}`);

  console.log('This is the rendered element', this.$()[0]);
  assert.ok(false);
});

我有一个带有这样的目录结构的ember-addon:

addon/
.. components/
.... my-component/
...... component.js
...... style.less
...... template.hbs   
app/  
.. components/
.... my-component.js
...... component.js
tests/  
.. integration/  
.... components/  
...... my-component-test.js  

ember如何确定{{my-component}}的位置?

这与此一脉相承:
How does Ember-CLI precompile templates?

编辑1

根据评论,我通过导入/导出常规app组件与addon组件相关联。

app/components/my-component/component.js
export { default } from 'my-application/components/my-component'  

但是,控制台日志只显示:

This is the rendered element <div id="ember234 class="ember-view">
                               <!---->
                             </div>

1 个答案:

答案 0 :(得分:2)

按惯例。

Ember尝试在my-component目录或app/components目录或app/components/templates目录下找到名为app/helpers的文件。

如果您在my-component目录下定义addon/components,则需要在app/components目录或tests/dummy/app/components目录下重新定义,例如:

export { default } from 'my-addon/components/my-component';