编写Ember.js组件集成测试子组件

时间:2021-04-30 15:39:21

I am attempting to follow Alisdar's new Itegration tests instead of doing unit testing on my ember component.

我试图遵循Alisdar的新Itegration测试,而不是在我的ember组件上进行单元测试。

I really like the new approach, but I have a problem when testing components which calls another component in its' view.

我真的很喜欢这种新方法,但在测试其视图中调用另一个组件的组件时遇到了问题。

alpha component:

alpha分量:

App.TestAlphaComponent = Ember.Component.extend({
  listWords: []
});

alpha component view uses beta component:

alpha组件视图使用beta组件:

{{#each listNumbers as num}}
  {{test-beta word=num}}
{{/each}}

beta component:

beta组件:

App.TestBetaComponent = Ember.Component.extend({
  word: 'hello world' 
});

beta component view:

beta组件视图:

<h1>{{ word }} </h2>

Mocha Chai Integration test for TestAlphaComponent

TestAphaComponent的Mocha Chai集成测试

import Ember from 'ember';
import { expect } from 'chai';
import {
  describeComponent,
  it
} from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';
import tHelper from "ember-i18n/helper";
import testBeta from "app/components/test-beta";

var foo;

describeComponent(
  'test-alpha',
  'Integration: testAlphaComponent',
  {
    integration: true
  },
  function() {
    beforeEach(function () {
      this.container.lookup('service:i18n').set('locale', 'en');
      this.registry.register('helper:t', tHelper);
      this.registry.register(
        'component:test-beta',
        testBeta
      );

      Ember.run(this, 'set','foo', ['foo','bar','baz']);
      this.render(hbs`{{test-alpha listWords=foo}}`);
    });
    it('prints foo bar baz in h1s', function() {
        expect($('h1').to.have.length(3);
    });
  });
);

my test fails. testBeta is never called, nor does it complain about missing components. What is the correct way to inject testBetaComponent into testAlpha's integration test environment?

我的测试失败了。 testBeta永远不会被调用,也不会抱怨缺少组件。将testBetaComponent注入testAlpha的集成测试环境的正确方法是什么?

1 个解决方案

#1


1  

Components need to have a dash in their names. Once you add a dash, subcomponents will be added automatically. See the note:

组件需要在其名称中包含破折号。添加短划线后,将自动添加子组件。见说明:

http://guides.emberjs.com/v1.13.0/components/defining-a-component/

http://guides.emberjs.com/v1.13.0/components/defining-a-component/

#1


1  

Components need to have a dash in their names. Once you add a dash, subcomponents will be added automatically. See the note:

组件需要在其名称中包含破折号。添加短划线后,将自动添加子组件。见说明:

http://guides.emberjs.com/v1.13.0/components/defining-a-component/

http://guides.emberjs.com/v1.13.0/components/defining-a-component/