Skip to content

Commit 1e3b7d0

Browse files
committed
fix: does not throw an error if KeyboardEvent has no key
1 parent a8a029e commit 1e3b7d0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

projects/ngx-raptorize/src/lib/konamiCode.directive.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ describe('KonamiCodeDirective', () => {
3636
fixture.detectChanges();
3737
});
3838

39+
it('should do nothing if the event has no key', () => {
40+
document.dispatchEvent(new Event('keydown'));
41+
});
42+
3943
describe('when proper sequence is entered', () => {
4044
it('should trigger konami event', () => {
4145
document.dispatchEvent(upArrow);

projects/ngx-raptorize/src/lib/konamiCode.directive.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export class KonamiCodeDirective {
2424

2525
@HostListener('document:keydown', ['$event'])
2626
handleKeyboardEvent(event: KeyboardEvent) {
27+
if (!event.key) {
28+
return;
29+
}
2730
const key = event.key.toString();
2831

2932
if (key) {

0 commit comments

Comments
 (0)