Unable to enter numbers in an input using `trigger()`
See original GitHub issueVersion
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 there
Steps to reproduce
Following the keyboard example from the documentation, I’m trying to input arbitrary keys into an input.
- Have a component
VueInput
that generated a top levelinput
DOM element<vue-input type='text'>
- With
vue-test-utils
, try to enter the keyshome
then1
using:
describe('Dummy VueInput.vue', () => {
it('should accept number keys', () => {
const wrapper = mount(VueInput);
const input = wrapper.find('input');
expect(input.element.value).toEqual('');
// Test inputting a number
input.trigger('click'); //FIXME Is this really needed? Isn't the focus already on the input since it's the generated DOM element?
input.trigger('keydown.home');
input.trigger('keydown', { //FIXME Fails
key: '1',
keyCode: 49,
which: 49,
});
expect(input.is('input')).toBe(true);
expect(input.element.value).toEqual('1');
});
});
What is expected?
The input
element value
should be 1
.
What is actually happening?
The input
element value
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 (like 1
, then 5
, then 8
, perhaps using something like wrapper.keys('158')
? (see how it’s done in Selenium-based webdriver.io in that example)).
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:15 (2 by maintainers)
Top Results From Across the Web
Trigger a button click with JavaScript on the Enter key in a text ...
And, I only want the Enter key to click this specific button if it is pressed from within this one text box, nothing...
Read more >Solved: OnChange() of a textInput doesn't work when enter
Solved: Hi, I have a Text Input object. The "format" field is set to Number. If I am in the Text Input and...
Read more >Why the number input is the worst input - Stack Overflow Blog
Chances are likely that you used the input type="number ” because you expected an integer to represent age or quantity. However, the number...
Read more >Activate a Stateflow Chart by Sending Input Events - MathWorks
Activate a Stateflow Chart by Using Edge Triggers. An edge-triggered input event causes a Stateflow chart to execute during the current time step...
Read more >25.3.1 Trigger Syntax and Examples - MySQL :: Developer Zone
Here is a simple example that associates a trigger with a table, to activate for INSERT operations. The trigger acts as an accumulator,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
+1 @AlexandreBonneau , I’m currently facing exactly the same issue.
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
vue-autoNumeric
component, setting theinput.value
directly (usinginput.value = 'foo'
) is managed differently than when changing the input value manually.In the former case, a
watch
on thevalue
is used, while on the latter thekeydown
,keypress
,keyup
events are closely monitored by the AutoNumeric library.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
vue-autonumeric
component and the value1,234,567.89
in it, if the caret is placed here1,234,5|67.89
and you enter a singleArrowLeft
key, then the result should be1,234|,567.89
(not1,234,|567.89
).I guess if vue-test-utils
trigger()
function does not simulatekey*
events, all this is untestable.Could you please confirm?