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

Add setChecked and setValue methods #530

Closed
eddyerburgh opened this issue Apr 14, 2018 · 7 comments
Closed

Add setChecked and setValue methods #530

eddyerburgh opened this issue Apr 14, 2018 · 7 comments

Comments

@eddyerburgh
Copy link
Member

eddyerburgh commented Apr 14, 2018

What problem does this feature solve?

Changing the value so that the v-model is updated can be confusing:

const input = wrapper.find('input[type="text"]')
input.element.value = 'some value' // input element value is changed, v-model is not
input.trigger('input') // v-model updated
const radioInput = wrapper.find('input[type="radio"]')
radioInput.element.checked = true // input element value is changed, v-model is not
radioInput.trigger('input') // v-model not updated
radioInput.trigger('change') // v-model updated

What does the proposed API look like?

const input = wrapper.find('input[type="text"]')
input.setValue('some value')
const radioInput = wrapper.find('input[type="radio"]')
radioInput.setChecked()
const option = wrapper.find('option')
option.setSelected()
@eddyerburgh eddyerburgh changed the title Add setChecked and setValue helpers Add setChecked and setValue methods Apr 14, 2018
@14nrv
Copy link

14nrv commented Apr 16, 2018

Hi, you should take a look to mwangaben-vthelpers which provides some helpers for vue-test-utils like b.type(text, selector) :

type(text, input) {
  let node = this.find(input)
  node.element.value = text
  node.trigger('input')
}

@38elements
Copy link
Contributor

IMHO,
Since type reminds keydown-event, I think that type is not appropriate.

@beyer-martin
Copy link
Contributor

@eddyerburgh are you working on this? If not I believe I can do it

@eddyerburgh
Copy link
Member Author

@beyersito I'm not currently working on it, it would be great if you could :)

@beyer-martin
Copy link
Contributor

@eddyerburgh Will do then, I'll start with setValue

@beyer-martin
Copy link
Contributor

beyer-martin commented Apr 24, 2018

I've started with setValue, I would be great if you could check if I started correctly.

I have a few doubts:

  1. setValue could work on the following inputs: text like inputs (text, email, ...), select, checkbox. The triggered event will follow v-model source.

  2. setChecked could work on radios and in checkboxes receiving a boolean parameter.

  3. Should it validate that the wrapper is compatible with the method?

  4. What to do if the wrapper is a component

Sorry to bother this much

Thanks!

@eddyerburgh
Copy link
Member Author

  1. I think it should work on all text control inputs, although I've only tested text and email. Can you check which elements it works on? Here's a full list of input types—https://html.spec.whatwg.org/multipage/input.html#attr-input-type-keywords

  2. Yes, setChecked should take a boolean

  3. Yes, it should throw an error if the wrapper element won't be affected

  4. A component wrapper always contains an element, so it should behave the same way.

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

4 participants