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

trigger keybord event with key property isn't working in v1.1.4 #1824

Closed
andreeapanait99 opened this issue Apr 13, 2021 · 0 comments
Closed

Comments

@andreeapanait99
Copy link

Subject of the issue

After the release of the 1.1.4 version, some of my tests that cover keyboard events fail. To be more specific, the tests in which I pass the key as a property of the event. This way is described in VTU documentation (https://vue-test-utils.vuejs.org/guides/dom-events.html#keyboard-example):

await wrapper.trigger('keydown', {
      key: 'a'
})

I could replace all keys with their respective keyCodes in my tests, however since this method is specified in the official docs and it was working in version 1.1.3 and below, I belive this is a bug.

Steps to reproduce

Let's take a simple Vue component. In template:
<div @keyup="$_handleKeyUp"> </div>

In script:

$_handleKeyUp(event) {
            if (event.key === KEY_VALUE.SPACE || event.key === KEY_VALUE.ENTER) {
                // do sth
            }
}

In tests, I want to verify if that something happens. So, I trigger an event with key ENTER.

await root.trigger('keyup', {
           key: 'Enter'
});

Expected behaviour

The test should pass.

Actual behaviour

The test fails. This also applies to any other keys I have tested (space - ' ', left - ArrowLeft, right - ArrowRight).

It's worth mentioning that replacing key with its respective keyCode does indeed make the test pass.

await root.trigger('keyup', {
           keyCode: 13
});

Passing the key as a modifier also works:

await root.trigger('keyup.enter');

Downgrading to version 1.1.3 also makes the tests pass.

Possible Solution

I belive this could be because of the modifications done in #1808.
I also noticed you don't have any test for these type of key events (with key as a parameter), or at least I could only find ones with keyCodes or modifiers; it might be worth adding a tests for this case as well to prevent further issues.

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

1 participant