I'm trying to generate a KeyboardEvent in my Typescript code.
const arrowLeft = new KeyboardEvent('keydown', { key: 'ArrowLeft' });
console.log(arrowLeft.keyCode, arrowLeft.key, arrowLeft.code);
When I check the value of arrowLeft.keyCode, I expect it to be 37. However, I see 0, 'Left', ''
instead. The issue is that I cannot manually set the keyCode as it is read-only in the KeyboardEvent interface.
Does anyone know if this is a problem specific to Typescript? How can I create an event with a keycode of 37? This test is part of my Angular Component testing process.