From d7d0df0bae978a023d66f9b675aff4e7f9a096da Mon Sep 17 00:00:00 2001 From: Justin Wolfe Date: Thu, 11 Nov 2021 14:46:07 -0800 Subject: [PATCH 1/2] remove the warning and update the test --- src/__tests__/useChannel.tsx | 12 +++++++----- src/core/useChannel.ts | 10 ++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/__tests__/useChannel.tsx b/src/__tests__/useChannel.tsx index 8efe361..2ba3b4c 100644 --- a/src/__tests__/useChannel.tsx +++ b/src/__tests__/useChannel.tsx @@ -2,18 +2,20 @@ import { PusherChannelMock } from "pusher-js-mock"; import React from "react"; import { renderHook } from "@testing-library/react-hooks"; import { renderHookWithProvider } from "../testUtils"; -import { useChannel, NO_CHANNEL_NAME_WARNING } from "../core/useChannel"; +import { useChannel } from "../core/useChannel"; import { __PusherContext } from "../core/PusherProvider"; describe("useChannel()", () => { - test("should throw an error when no channelName present", () => { + test("should return undefined when channelName is falsy", () => { const wrapper: React.FC = (props) => ( <__PusherContext.Provider value={{ client: {} as any }} {...props} /> ); - jest.spyOn(console, "warn"); - renderHook(() => useChannel(undefined), { wrapper }); - expect(console.warn).toHaveBeenCalledWith(NO_CHANNEL_NAME_WARNING); + const { result } = renderHook(() => useChannel(""), { + wrapper, + }); + + expect(result.current).toBeUndefined(); }); test("should return undefined if no pusher client present", () => { diff --git a/src/core/useChannel.ts b/src/core/useChannel.ts index 750cf6e..cf04526 100644 --- a/src/core/useChannel.ts +++ b/src/core/useChannel.ts @@ -16,9 +16,6 @@ import { usePusher } from "./usePusher"; * ``` */ -export const NO_CHANNEL_NAME_WARNING = - "No channel name passed to useChannel. No channel has been subscribed to."; - export function useChannel( channelName: string | undefined ) { @@ -28,11 +25,8 @@ export function useChannel( /** Return early if there's no client */ if (!client) return; - /** Return early and warn if there's no channel */ - if (!channelName) { - console.warn(NO_CHANNEL_NAME_WARNING); - return; - } + /** Return early if channel name is falsy */ + if (!channelName) return; /** Subscribe to channel and set it in state */ const pusherChannel = client.subscribe(channelName); From b1834f5349dd22d3425ee6e1a6b379082dbb51a4 Mon Sep 17 00:00:00 2001 From: Justin Wolfe Date: Thu, 11 Nov 2021 14:57:38 -0800 Subject: [PATCH 2/2] Update _core_usechannel_.html --- docs/modules/_core_usechannel_.html | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/modules/_core_usechannel_.html b/docs/modules/_core_usechannel_.html index 0da9c73..fd29bdb 100644 --- a/docs/modules/_core_usechannel_.html +++ b/docs/modules/_core_usechannel_.html @@ -88,9 +88,6 @@

Functions

Variables

- -

Const NO_CHANNEL_NAME_WARNING

-
NO_CHANNEL_NAME_WARNING: "No channel name passed to useChannel. No channel has been subscribed to." = "No channel name passed to useChannel. No channel has been subscribed to."