Skip to content

Commit

Permalink
Add debugEventTarget function
Browse files Browse the repository at this point in the history
  • Loading branch information
allevo committed Jun 20, 2024
1 parent 3a14188 commit c1eaac9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
18 changes: 18 additions & 0 deletions packages/seqflow-js/src/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function debugEventTarget(ev: EventTarget): EventTarget {
const oldAddEventListener = ev.addEventListener;
ev.addEventListener = (
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
) => {
console.log("addEventListener", type);
return oldAddEventListener.call(ev, type, listener, options);
};
const oldDispatchEvent = ev.dispatchEvent;
ev.dispatchEvent = (event: Event) => {
console.log("dispatchEvent", event.type);
return oldDispatchEvent.call(ev, event);
};

return ev;
}
1 change: 1 addition & 0 deletions packages/seqflow-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type Router,
} from "./router";
import { domEvent, domainEvent, navigationEvent } from "./typedEvents";
export { debugEventTarget } from "./debug";

export { BrowserRouter, type Router, NavigationEvent, InMemoryRouter };
export type { EventAsyncGenerator, CustomEventAsyncGenerator } from "./events";
Expand Down
4 changes: 1 addition & 3 deletions packages/seqflow-js/tests/types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ test("render simple button", async () => {
},
{},
);
expect(document.body.innerHTML).toBe(
'<input type="button" list="button">',
);
expect(document.body.innerHTML).toBe('<input type="button" list="button">');
});

0 comments on commit c1eaac9

Please sign in to comment.