Search code examples
ember.jsember-cliember-testing

Integration test for component containing a component


I have a component that uses another component. But it doesn't work because the test for the first component says it's missing a helper called curit-select.

In 0.10 you could add a needs to themoduleForComponent` function but doing that now will force it to unit-testing mode. (see)

You do not require dependencies through needs:. Doing so will force the test into unit mode.

component 1:

<div class='change-device-status'>
  Status: {{curit-select content=statuses selection=device.status}}
  <button class="save-button" {{action 'save'}}>opslaan</button>
</div>

component 2:

<select {{action 'change' on='change'}}>
  {{#if prompt}}
    <option disabled selected={{is-not selection}}>
      {{prompt}}
    </option>
  {{/if}}

  {{#each content key="@identity" as |item|}}
    <option value="{{read-path item optionValuePath}}"
            selected={{is-equal item selection}}>
      {{read-path item optionLabelPath}}
     </option>
  {{/each}}
</select>

Now I'm trying to write an integration test for the first component:

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

moduleForComponent('change-device-status', 'Integration | Component | change device status', {
  integration: true
});

test('it renders', function(assert) {
  assert.expect(3);

  // Set any properties with this.set('myProperty', 'value');
  // Handle any actions with this.on('myAction', function(val) { ... });

  this.set('dev', {
    status: 'InUse'
  });

  this.render(hbs`{{change-device-status content=dev}}`);

  assert.equals(this.$().text().trim(), '');
});

Solution

  • It'll just work! Remember restart ember serve.