How does ember-qunit render components in integration testing?

南楼画角 提交于 2019-12-11 04:52:47

问题


Here is a basic component / integration test for 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);
});

I have an ember-addon with a directory structure like this:

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

How does ember determine where {{my-component}} is?

This is kind of in the same vein as this:
How does Ember-CLI precompile templates?

Edit 1

As per the comments, I've linked the regular app component to the addon component by just importing / exporting it.

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

However, the console log only shows this:

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

回答1:


By convention.

Ember try to find a file named my-component under your app/components directory or app/components/templates directory or app/helpers directory.

If you define my-component under your addon/components directory, you need to re-define it under your app/components directory or tests/dummy/app/components directory such as:

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


来源:https://stackoverflow.com/questions/39236852/how-does-ember-qunit-render-components-in-integration-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!