Skip to content

Commit 4157613

Browse files
committed
wip
1 parent eb0a42f commit 4157613

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

packages/react/tests/use-echo.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,11 @@ describe("useEchoNotification hook", async () => {
10411041
echoModule.useEchoNotification(channelName, mockCallback),
10421042
);
10431043

1044-
expect(echoInstance.private).toHaveBeenCalledWith(channelName);
1044+
const channel = echoInstance.private(channelName);
10451045

10461046
expect(() => unmount()).not.toThrow();
10471047

1048+
expect(channel.stopListeningForNotification).toHaveBeenCalled();
10481049
expect(echoInstance.leaveChannel).toHaveBeenCalledWith(
10491050
`private-${channelName}`,
10501051
);
@@ -1113,8 +1114,11 @@ describe("useEchoNotification hook", async () => {
11131114
expect(channel.notification).toHaveBeenCalledTimes(1);
11141115

11151116
result.current.stopListening();
1117+
expect(channel.stopListeningForNotification).toHaveBeenCalled();
1118+
11161119
result.current.listen();
11171120

1121+
// notification should still only be called once due to initialized check
11181122
expect(channel.notification).toHaveBeenCalledTimes(1);
11191123
});
11201124

packages/vue/src/composables/useEcho.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ export const useEchoNotification = <
245245
listen();
246246
});
247247

248+
onUnmounted(() => {
249+
stopListening();
250+
});
251+
248252
return {
249253
...result,
250254
/**

packages/vue/tests/useEcho.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,11 @@ describe("useEchoNotification hook", async () => {
924924
undefined,
925925
);
926926

927-
expect(echoInstance.private).toHaveBeenCalledWith(channelName);
927+
const channel = echoInstance.private(channelName);
928928

929929
wrapper.unmount();
930930

931+
expect(channel.stopListeningForNotification).toHaveBeenCalled();
931932
expect(echoInstance.leaveChannel).toHaveBeenCalledWith(
932933
`private-${channelName}`,
933934
);

0 commit comments

Comments
 (0)