Skip to content

Commit

Permalink
fix(esl-event-listener): fix isEventDescriptor check for incorrect …
Browse files Browse the repository at this point in the history
…type of event key
  • Loading branch information
ala-n committed Jan 30, 2023
1 parent af44e49 commit 729b486
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/modules/esl-event-listener/core/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ function getDescriptorsKeysFor<T extends object>(host: T): (keyof T)[] {
}

/** Type guard to check if the passed function is typeof {@link ESLListenerDescriptorFn} */
export function isEventDescriptor(obj: unknown): obj is ESLListenerDescriptorFn {
return typeof obj === 'function' && Object.hasOwnProperty.call(obj, 'event');
export function isEventDescriptor(obj: any): obj is ESLListenerDescriptorFn {
if (typeof obj !== 'function' || !Object.hasOwnProperty.call(obj, 'event')) return false;
return typeof obj.event === 'string' || typeof obj.event === 'function';
}

/** Gets {@link ESLListenerDescriptorFn}s of the passed object */
Expand Down
6 changes: 5 additions & 1 deletion src/modules/esl-event-listener/test/descriptor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {ESLEventUtils} from '../core';
describe('dom/events: ESLEventUtils: ESLListenerDescriptor Utils', () => {
describe('ESLEventUtils.isEventDescriptor', () => {
function fakeDesc() {}
descEvent.event = false;
fakeDesc.event = false;

function fakeDesc2() {}
fakeDesc2.event = {};

function descEvent() {}
descEvent.event = 'event';
Expand All @@ -19,6 +22,7 @@ describe('dom/events: ESLEventUtils: ESLListenerDescriptor Utils', () => {
[{event: ''}, false],
[function noop() {}, false],
[fakeDesc, false],
[fakeDesc2, false],

[descEvent, true],
[descEventProvider, true]
Expand Down

0 comments on commit 729b486

Please # to comment.