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

Feature: setSelected() with value or setValue() on select #775

Closed
VictorCazanave opened this issue Jun 29, 2018 · 7 comments
Closed

Feature: setSelected() with value or setValue() on select #775

VictorCazanave opened this issue Jun 29, 2018 · 7 comments

Comments

@VictorCazanave
Copy link
Contributor

What problem does this feature solve?

In my tests I often use the same value (stored in a variable) to select an option and check the assertion.

Then the current setSelect() is not very convenient :

const values = ['value0', 'value1']
const options = wrapper.find('select').findAll('option')
const index = 1
options.at(index).setSelected()
expect(/* something */).toEqual(values[index])

Same when selecting an option by value :

const newValue = 'value1'
const option = wrapper.find('select').find(`option[value="${newValue}"]`)
option.setSelected()
expect(/* something */).toEqual(newValue)

So I prefer to use :

const select = wrapper.find('select')
const newValue = 'value1'
select.element.value = newValue
select.trigger('change')
expect(/* something */).toEqual(newValue)

What does the proposed API look like?

const select = wrapper.find('select')
select.setSelected('value')
// or
select.setValue('value') // Trigger 'change' event instead of 'input'
// or a new method
select.setSelectedValue('value')
@VictorCazanave VictorCazanave changed the title setSelected() with value or setValue() on select Feature: setSelected() with value or setValue() on select Jun 29, 2018
@VictorCazanave
Copy link
Contributor Author

@eddyerburgh if you agree with this feature, I may have time to (try to) make a PR this week 😏

@eddyerburgh
Copy link
Member

I like the idea, but not sure how it would work when you have multiple options with the same value?

@VictorCazanave
Copy link
Contributor Author

I always use options with unique values.
For what kind of use case do you need options with the same value?

Maybe this feature should also accept an Array as parameter to handle multiple select:

select.setSelected(['value0', 'value1']);

@eddyerburgh
Copy link
Member

eddyerburgh commented Jul 10, 2018

Ok, how about updating setValue to set the value of a selected element. Then there's no need to handle multiple options with the same value

@VictorCazanave
Copy link
Contributor Author

It sounds good to me

@VictorCazanave
Copy link
Contributor Author

May I create a PR or does this feature need more discussion/approval?

@eddyerburgh
Copy link
Member

Yes you can create a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants