Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where does the "ember.run" belong when integration testing? #203

Closed
toranb opened this issue Oct 29, 2015 · 2 comments
Closed

Where does the "ember.run" belong when integration testing? #203

toranb opened this issue Oct 29, 2015 · 2 comments

Comments

@toranb
Copy link

toranb commented Oct 29, 2015

I've become a huge integration test fan boy recently and find that I often need to wrap my trigger (change/input/etc) with ember.run like so

test('on change will work as expected', function(assert) {
    let issue = Issue.create({id: 1, subject: 'Broken'});
    let one = Status.create({id: 8, name: 'Open', issues: []});
    let two = Status.create({id: 9, name: 'Closed', issues: [1]});
    this.set('model', issue);
    this.set('statuses', Ember.A([one, two]));
    this.render(hbs`{{issue-detail model=model statuses=statuses}}`);
    let $component = this.$(".my-select-here");
    Ember.run(() => {
        $component.val(9).trigger('change');
    });
    //assert some stuff
});

The production select looks something like this

<select class="form-control my-select-here" onchange={{action "changed_status" value="target.value"}}>
{{#each statuses as |status|}}
<option value={{status.id}} selected={{is-equal model.status.id status.id}}>{{status.name}}</option>
{{/each}}
</select>

In the action itself I do some type of "set" (which causes the runloop error to pop up in the test you see above). Should I wrap the trigger change in the intergration test or instead should I ember.run in the action that's invoked from the "onchange" event (and why) ?

https://github.com/toranb/ember-cli-selectize/blob/master/tests/integration/components/issue-detail-test.js#L24-L26

@rwjblue
Copy link
Member

rwjblue commented Oct 29, 2015

In 2.2 closure actions will be properly wrapped in a run loop (just like non-closure actions).

For now I would add to your tests (or make a simple helper function that you use). I intend to expose some nice helpers for component integration tests (things like 'click', 'fillin', etc that you get for free in acceptance tests), so making a small helper function would make that an easy refactor in the future.

@toranb
Copy link
Author

toranb commented Oct 29, 2015

Glad to know I got this right the first time around :)

thanks for the quick reply @rwjblue

@toranb toranb closed this as completed Oct 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants