David Chan
David Chan

Reputation: 7505

Writing Ember.js component Integration Tests with sub components

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

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

alpha component:

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

alpha component view uses beta component:

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

beta component:

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

beta component view:

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

Mocha Chai Integration test for TestAlphaComponent

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?

Upvotes: 0

Views: 809

Answers (1)

Gaurav
Gaurav

Reputation: 12796

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/

Upvotes: 1

Related Questions