Skip to content

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

Closed
@andreeapanait99

Description

@andreeapanait99

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions