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

Problem with keyboard event simulating #102

Open
riophae opened this issue Aug 8, 2017 · 9 comments
Open

Problem with keyboard event simulating #102

riophae opened this issue Aug 8, 2017 · 9 comments

Comments

@riophae
Copy link
Contributor

riophae commented Aug 8, 2017

Though it's possible to simulate some specific keys to test keyboard events, it's actually too limited - only a few keys are allowed:

avoriaz/src/Wrapper.js

Lines 373 to 383 in c6fa79e

const modifiers = {
enter: 13,
tab: 9,
delete: 46,
esc: 27,
space: 32,
up: 38,
down: 40,
left: 37,
right: 39,
};

So I think it's necessary to make it possible to test any keys.

Also, as this article suggests, it's best to watch event.which property rather than event.keyCode. But avoriaz has only set value for keyCode property. If only event.which has been used by the application logic, then we can not test that at all.

avoriaz/src/Wrapper.js

Lines 397 to 400 in c6fa79e

if (event.length === 2) {
// $FlowIgnore
eventObject.keyCode = modifiers[event[1]];
}

In general, the synthetic event should be able to be freely modified to suit any specific needs:

wrapper.trigger('keyup', { which: 8 }) // backspace key
@eddyerburgh
Copy link
Owner

I think this is a great suggestion. Are you able to implement it? We could release, along with your other changes, in 4.0.0

@riophae
Copy link
Contributor Author

riophae commented Aug 9, 2017

Yeah, no problem!

@riophae
Copy link
Contributor Author

riophae commented Aug 10, 2017

I think we could outsource the work to this module https://github.com/KenanY/create-event ?

@eddyerburgh
Copy link
Owner

eddyerburgh commented Aug 10, 2017 via email

@riophae
Copy link
Contributor Author

riophae commented Aug 14, 2017

These days I have spent some time reading the source code of triggerhappy. It provides a lots more features, including touch events testing. I think we can learn something from it and jest and we will have a lot to discuss about.
But for now, I think there is an urgent need for testing keyboard events and we should implement that as soon as possible. I'll outsource the work to create-event for the time being.

@mathijswesterhof
Copy link

mathijswesterhof commented Aug 27, 2018

I don't know if anyone is already working on this issue/enhancement, but can that person also look at the feature of key + shiftKey=true (and altKey) because that is currently also not functioning. in specific this line wrapper.find('input')[0].trigger('keyup', { keycode: 53, shiftKey: true }); (in this case %)

@riophae
Copy link
Contributor Author

riophae commented Aug 30, 2018

@mathijswesterhof Hi, I'm not working on this. Sorry.

@eddyerburgh
Copy link
Owner

This project isn't actively maintained, although I'm happy to accept PRs.

I recommend using Vue Test Utils, which is based on avoriaz—https://github.com/vuejs/vue-test-utils

@mathijswesterhof
Copy link

good to know, i'll try to migrate then, see if the problem is solvable on vue-test-utils. if not I'll make a pr there

Repository owner deleted a comment from jaapio Jan 23, 2019
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

3 participants