How do you trigger selecting an <option>
in a select
element in an integration test? select2 is simple enough: Simulate a ember-select2 selection in ember integration test
Simulate a select selection in ember integration test
Do you want to select something or trigger the event? –
Zales
@Kitler ets just say I want to select the first option, from the qunit ember-cli test. –
Elative
Have you tried clicking on the list and then clicking on the first option? –
Zales
just to clarify -is this a integration test or an acceptance test (ie- acceptance has the fillIn helpers/integration does not) –
Kazimir
@ToranBillups acceptnace test –
Elative
A basic example for ember 1.12 or 1.13+ would use the fillIn helper. I just haven't used it with a jquery select like the one you mention above. Give this a try and report back :)
visit("/foobar");
var firstOption = find(".my-select option:eq(0)");
fillIn(".my-select", firstOption.val());
andThen(function() {
assert.equal(find(".my-select").val(), 78); //assuming 78 is the first options value ...
});
Thanks, but what if I don't know the values of the select beforehand? –
Elative
So do you have an option you'd like to select? If not ... Maybe explain more about how this should work so I can help :) –
Kazimir
I would just like to trigger the selection of the first option without knowing the value. –
Elative
Ah, that should be a simple css selector update (check the code above and let me know if you still don't have a working test). –
Kazimir
@ToranBillups Can it fire "change" event? If no, how can if fire it? If I call ".change()" it fails with "Adapter operation failed". –
Screed
Looking at the ember source it should be a simple trigger("input") –
Kazimir
gist.github.com/toranb/… –
Kazimir
I've had to do this for the underlying event code to be triggered (Ember 2.16):
find('select#my-select').val('foo').trigger('change');
nice to see ember is still alive in the wild, still get many clients asking for it? –
Elative
@Elative I'm working on an old project, but I think teams tend to choose react for new projects now. The ember community still looks active though! –
Parian
© 2022 - 2024 — McMap. All rights reserved.