Skip to content

Commit

Permalink
fix: does not throw an error if KeyboardEvent has no key
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaudAV committed Oct 6, 2020
1 parent a8a029e commit 1e3b7d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions projects/ngx-raptorize/src/lib/konamiCode.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ describe('KonamiCodeDirective', () => {
fixture.detectChanges();
});

it('should do nothing if the event has no key', () => {
document.dispatchEvent(new Event('keydown'));
});

describe('when proper sequence is entered', () => {
it('should trigger konami event', () => {
document.dispatchEvent(upArrow);
Expand Down
3 changes: 3 additions & 0 deletions projects/ngx-raptorize/src/lib/konamiCode.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class KonamiCodeDirective {

@HostListener('document:keydown', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
if (!event.key) {
return;
}
const key = event.key.toString();

if (key) {
Expand Down

0 comments on commit 1e3b7d0

Please sign in to comment.