ngneat/spectator

dispatchKeyboardEvent keydown Control event.ctrlKey is not true

Julian-B90 opened this issue · 0 comments

Is this a regression?

Yes

Description

I have an Angular app in which I have a HostListener.

   @HostListener('document:keydown', ['$event'])
    onKeyDown(event: KeyboardEvent) {
        // Handle keydown event here
        if (event.ctrlKey || event.metaKey) {
            this.service.ctrlMode(true);
        }
    }

This is my test:

    it('should be press ctrKey', () => {
        spectator.dispatchKeyboardEvent(spectator.element, 'keydown', { key: 'a', keyCode: 65 });

        expect(service.ctrlMode()).toBe(false);

        spectator.dispatchKeyboardEvent(spectator.element, 'keydown', { key: 'Control', keyCode: 17 });

        expect(service.ctrlMode()).toBe(true);
    });

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

When I call spectator.dispatchKeyboardEvent(spectator.element, 'keydown', { key: 'Control', keyCode: 17 }); the evten.ctrlKey are not true.

Please provide the environment you discovered this bug in

"jest": "^29.5.0",
"@ngneat/spectator": "^15.0.1",

Anything else?

No response

Do you want to create a pull request?

No