Skip to content

Unable to update input value via keydown/keyup/keypress #372

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

Closed
metacurb opened this issue Jan 22, 2018 · 6 comments
Closed

Unable to update input value via keydown/keyup/keypress #372

metacurb opened this issue Jan 22, 2018 · 6 comments

Comments

@metacurb
Copy link

metacurb commented Jan 22, 2018

Version

1.0.0-beta.10
Jest 22.0.4

Reproduction link

https://jsfiddle.net/xvL6q27m/

Steps to reproduce

Test attached component using Jest, and vue-test-utils

What is expected?

The value inside the data of the component should update, and be a.

What is actually happening?

Nothing, the value doesn't change, and the input.element.value is also empty. The test always fails.

Expected value to be (using Object.is):
  "a"
Received:
  ""

I tested this with beta.9, and then again with beta.11 (not on the list)

@eddyerburgh
Copy link
Member

Hi @BeauAgst, thanks for the bug report.

Can you make a reproduction using this JSFiddle as a base: https://jsfiddle.net/eddyerburgh/sghur81m/3/

@metacurb
Copy link
Author

metacurb commented Jan 22, 2018

@eddyerburgh apologies - https://jsfiddle.net/xvL6q27m/

I've updated the original issue to this link

@eddyerburgh
Copy link
Member

eddyerburgh commented Jan 23, 2018

No problem! It takes a bit of setup in JSFiddle. Thanks for the reproduction.

With a value, you need to set it on the element:

wrapper.element.value = ''

Then you can trigger an event that uses the value:

wrapper.trigger('keydown')

However, there's a problem with v-model, where changing the value isn't picked up by the model value—#345. We're working on a fix

@metacurb
Copy link
Author

Thanks for the prompt reply @eddyerburgh

That's fine, and how I was originally doing it for my @keyup method. However, I have since added @keydown (to validate keys being pressed and prevent them from being entered if they don't match a regex string)

What would your recommendation be on how to test that method? Am I correct to assume I won't be able to test it until that bug is fixed? Thanks!

For example: https://jsfiddle.net/bj81bhwo/
I am passing the event to this method, and checking for the key that was pressed.

@eddyerburgh
Copy link
Member

Yeah sorry, there isn't currently a way to test that.

One method I can think of is to allow you to pass a custom Event to trigger, then you could test that preventDefault was prevented.

If you'd like to use this feature, please make a feature-request issue 😀

@ankitsinghaniyaz
Copy link

ankitsinghaniyaz commented Nov 27, 2018

Is there a way to test this now?

I'm using vue-testing-libarary and saw a reference that the dom inputs cannot be updated due to a bug in vue-test-utils.

https://github.com/dfcook/vue-testing-library/blob/master/tests/__tests__/form.js

Edit

I'm also curious to know why the update to the dom node doesn't update the state? Because the values changed in the application via a browser does work fine.

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

3 participants