Skip to content

Commit

Permalink
šŸ· add metadata type to useEvent (test missing, pending pusher-js-mockā€¦
Browse files Browse the repository at this point in the history
ā€¦ update)
  • Loading branch information
mayteio committed Sep 18, 2020
1 parent 7b88e93 commit 7cc8563
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/__tests__/useEvent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Channel } from "pusher-js";
import { PusherChannelMock } from "pusher-js-mock";
import { Channel, PresenceChannel } from "pusher-js";
import { PusherChannelMock, PusherPresenceChannelMock } from "pusher-js-mock";
import { renderHook } from "@testing-library/react-hooks";
import { useEvent } from "../core/useEvent";

Expand All @@ -26,4 +26,20 @@ describe("useEvent()", () => {
channel.emit("event", {});
expect(listener).not.toHaveBeenCalled();
});

/** pusher-js-mock needs to be updated to test this */
test.skip("should accept metadata from presence channels", () => {
const listener = jest.fn();
const channel = new PusherPresenceChannelMock();
renderHook(() =>
useEvent(
(channel as unknown) as PresenceChannel,
"presence-event",
listener
)
);

// @ts-ignore
channel.emit("presence-event", {}, { user_id: "my-id" });
});
});
2 changes: 1 addition & 1 deletion src/core/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useEffect } from "react";
export function useEvent<D>(
channel: Channel | PresenceChannel | undefined,
eventName: string,
callback: (data?: D) => void
callback: (data?: D, metadata?: { user_id: string }) => void
) {
// error when required arguments aren't passed.
invariant(eventName, "Must supply eventName and callback to onEvent");
Expand Down

0 comments on commit 7cc8563

Please sign in to comment.