-
Notifications
You must be signed in to change notification settings - Fork 668
Unable to enter numbers in an input using trigger()
#484
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
Comments
For me, |
Unfortunately, I added the three |
If you want to have a working reproducible example, you can checkout the code from the Then: # Setup the repo
git clone -b issue_1 && cd vue-autoNumeric && yarn
# Build the component
yarn build
# Run the test with jest
yarn test You'll see all the tests that are currently failing, and if you want to check only the test that is the subject of this particular issue, change Note: the other tests are failing when they should not (you can check that everything works as expected when manually manipulating the examples page in |
For info, |
Dispatching an event with a keycode does not update an To test what happens when triggering an event on an element, you must set the value before calling wrapper.element.value = 'some value'
wrapper.trigger('change') There is an ongoing issue on testing v-model —#345 |
I'm not sure to follow; what do you mean by you must set the value manually? Using If simulating a I think this issue should not be closed. Anyway, does this means we currently have no way to test any vue components that allows a user to interacts with it (ie. component that mask the user input, or a password input that displays an help tooltip once 3 or more characters have been entered, etc.)? |
Trigger is a wrapper around You need to set the value directly: input.element.value = 'some value'
You can test those things by changing the value and making sure the component reacts correctly to it. |
I'm not seeing how "You can test those things by changing the value" in a case where masking is involved. For instance with the In the former case, a Moreover, setting the value directly cannot allows to test some keys that do not produce a change in the input value; for instance when you have the default settings on a I guess if vue-test-utils Could you please confirm? |
+1 @AlexandreBonneau , I'm currently facing exactly the same issue. |
This is closed, is that because it was fixed? I can't increment a value with trigger('keydown') either. |
Sets the value of a text-control input or select element and updates v-model bound data. Its worked Output = 'hello' Or Can do this way
So |
Why is this closed? I am preventing some inputs using the |
@pinutz23 Maybe you can do something like: const input = wrapper.find('input');
input.trigger('keydown', {
key: '1',
}; Also, you can check this example: https://vue-test-utils.vuejs.org/guides/dom-events.html#keyboard-example |
I also think this should be reopened. I have a component that has to prevent certain keypresses because of the way number inputs work. This behavior is impossible to test by setting the value. |
Not sure if this is related to the topic, yet this is also unable in vue-test-utils-next. It would be nice if we can do so. |
Version
1.0.0-beta.12
Reproduction link
https://codesandbox.io/s/n768kwm6wj
note: the dummy
VueInput
component and the spec code is correct, but I can't make vue-test-utils work thereSteps to reproduce
Following the keyboard example from the documentation, I'm trying to input arbitrary keys into an input.
VueInput
that generated a top levelinput
DOM element<vue-input type='text'>
vue-test-utils
, try to enter the keyshome
then1
using:What is expected?
The
input
elementvalue
should be1
.What is actually happening?
The
input
elementvalue
is unchanged and still equal to""
.Bonus question:
Do we need to manually (and painfully) convert each key we want to enter to its keyCode (
which
value), or is there a quicker and better way to enter multiple keys one after another in one go (like1
, then5
, then8
, perhaps using something likewrapper.keys('158')
? (see how it's done in Selenium-based webdriver.io in that example)).The text was updated successfully, but these errors were encountered: