Codev
Codev

Reputation: 1160

How can I test keydown events in Jasmine with specific keyCode on Angular2+

In my application I have an <input> field on which I want to trigger keydown events.

My Setup

How can I do this?

Upvotes: 3

Views: 2193

Answers (1)

Codev
Codev

Reputation: 1160

Found a solution. I created a function that can be called passing the key code as parameter:

function keyDown(key: number) {
    fixture.debugElement.query(By.css('input')).triggerEventHandler('keydown', { key: key });
}

Upvotes: 5

Related Questions