Reputation: 46300
I have this integration test:
test('can change chord text', function(assert) {
this.render(hbs`{{chart-editor-chord chord=chord}}`);
this.$().click();
assert.ok(!!this.$('.chord-input').length);
});
but the assertion fails, the component template looks like this:
<div {{action 'changeChord'}} class="measure-chord chord-big">
{{#if chord.editing}}
<input type="text" value="{{chord.name}}" class="chord-input">
{{else}}
{{chord.name}}
{{/if}}
</div>
and the component code:
import Ember from 'ember';
export default Ember.Component.extend({
store: Ember.inject.service(),
actions: {
changeChord() {
this.chord.set('editing', true);
}
}
});
I'm updating the chord
model in the changeChord()
action and it does work if I test in the browser, but the integration test fails. So, does this change in the model have to be rendered synchronously to the template? I tried using wait() in the test but that doesn't make a difference. So how should I test this?
Upvotes: 0
Views: 322
Reputation: 5955
It looks like your click helper is clicking the div that your component.js controls instead of the initial div in your template. If you specify the div in your click helper it should work:
this.$('.measure-chord').click();
Upvotes: 1
Reputation: 6221
While I'm trying to create a twiddle for you, I found three things:
chord
mock in your test?this.$('.measure-chord')
or this.$('.chord-big')
. this.chord.set
you should use this.get('chord').set
. Actually Ember.set(this, 'chord.isEditing', ...)
is even better.And bonus: You don't need a div
wrapper, component does this for you.
twiddles:
Upvotes: 1