diff --git a/README.md b/README.md index 40613da..c09ea80 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,55 @@ const Example = () => { This project was built using typescript, so types are built-in. Yeeeew! +## Testing + +Typed `PusherMock`, `PusherChannelMock` and `PusherPresenceChannelMock` utils are provided based on [`pusher-js-mock`](https://github.com/nikolalsvk/pusher-js-mock) (thanks mate 🙏). Use these to stub out the client and channels, with an additional `emit` method on the channel classes. + +Testing emitted events with jest can be achieved using `jest.mock` and `react-testing-library` (or `enzyme`, though your tests should reflect what the user should see **NOT** how the component handles events internally): + +```tsx +// Example.tsx +import React from "react"; +import { useChannel, useEvent } from "use-pusher"; + +const Example = () => { + const [title, setTitle] = useState(); + const channel = useChannel("my-channel"); + useEvent(channel, "title", ({ data }) => setTitle(data)); + + return {title}; +}; + +// Example.test.tsx +import { render, act } from "@testing-library/react"; +import { PusherMock, PusherChannelMock } from "use-pusher"; + +// mock out the result of the useChannel hook +const mockChannel = new PusherChannelMock(); +jest.mock("use-pusher", () => ({ + ...require.requireActual("use-pusher"), + useChannel: () => mockChannel +})); + +test("should show a title when it receives a title event", async () => { + // mock the client + const client = { current: new PusherMock("client-key", { cluster: "ap4" }) }; + + // render component and provider with a mocked context value + const { findByText } = render( + + + + ); + + // emit an event on the mocked channel + act(() => mockChannel.emit("title", { data: "Hello world" })); + + // assert expectations + expect(await findByText("Hello world")).toBeInTheDocument(); +}); +``` + ## Contributing 1. Clone the repository and run `yarn && yarn test:watch` diff --git a/docs/assets/js/search.js b/docs/assets/js/search.js index 5d76740..3d1d433 100644 --- a/docs/assets/js/search.js +++ b/docs/assets/js/search.js @@ -1,3 +1,3 @@ var typedoc = typedoc || {}; typedoc.search = typedoc.search || {}; - typedoc.search.data = {"kinds":{"1":"External module","32":"Variable","64":"Function","128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal"},"rows":[{"id":0,"kind":1,"name":"\"types\"","url":"modules/_types_.html","classes":"tsd-kind-external-module"},{"id":1,"kind":256,"name":"PusherContextValues","url":"interfaces/_types_.pushercontextvalues.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"types\""},{"id":2,"kind":1024,"name":"client","url":"interfaces/_types_.pushercontextvalues.html#client","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherContextValues"},{"id":3,"kind":1024,"name":"triggerEndpoint","url":"interfaces/_types_.pushercontextvalues.html#triggerendpoint","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherContextValues"},{"id":4,"kind":1024,"name":"pusherOptions","url":"interfaces/_types_.pushercontextvalues.html#pusheroptions","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherContextValues"},{"id":5,"kind":256,"name":"PusherProviderProps","url":"interfaces/_types_.pusherproviderprops.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"types\""},{"id":6,"kind":1024,"name":"clientKey","url":"interfaces/_types_.pusherproviderprops.html#clientkey","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherProviderProps"},{"id":7,"kind":1024,"name":"cluster","url":"interfaces/_types_.pusherproviderprops.html#cluster","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-overwrite","parent":"\"types\".PusherProviderProps"},{"id":8,"kind":1024,"name":"authEndpoint","url":"interfaces/_types_.pusherproviderprops.html#authendpoint","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-overwrite","parent":"\"types\".PusherProviderProps"},{"id":9,"kind":1024,"name":"auth","url":"interfaces/_types_.pusherproviderprops.html#auth","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-overwrite","parent":"\"types\".PusherProviderProps"},{"id":10,"kind":1024,"name":"triggerEndpoint","url":"interfaces/_types_.pusherproviderprops.html#triggerendpoint","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherProviderProps"},{"id":11,"kind":1024,"name":"defer","url":"interfaces/_types_.pusherproviderprops.html#defer","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherProviderProps"},{"id":12,"kind":1024,"name":"children","url":"interfaces/_types_.pusherproviderprops.html#children","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherProviderProps"},{"id":13,"kind":1024,"name":"forceTLS","url":"interfaces/_types_.pusherproviderprops.html#forcetls","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":14,"kind":1024,"name":"encrypted","url":"interfaces/_types_.pusherproviderprops.html#encrypted","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":15,"kind":1024,"name":"authTransport","url":"interfaces/_types_.pusherproviderprops.html#authtransport","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":16,"kind":1024,"name":"authorizer","url":"interfaces/_types_.pusherproviderprops.html#authorizer","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":17,"kind":1024,"name":"disableStats","url":"interfaces/_types_.pusherproviderprops.html#disablestats","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":18,"kind":1024,"name":"enabledTransports","url":"interfaces/_types_.pusherproviderprops.html#enabledtransports","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":19,"kind":1024,"name":"disabledTransports","url":"interfaces/_types_.pusherproviderprops.html#disabledtransports","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":20,"kind":1024,"name":"ignoreNullOrigin","url":"interfaces/_types_.pusherproviderprops.html#ignorenullorigin","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":21,"kind":1024,"name":"activityTimeout","url":"interfaces/_types_.pusherproviderprops.html#activitytimeout","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":22,"kind":1024,"name":"pongTimeout","url":"interfaces/_types_.pusherproviderprops.html#pongtimeout","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":23,"kind":1024,"name":"wsHost","url":"interfaces/_types_.pusherproviderprops.html#wshost","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":24,"kind":1024,"name":"wsPath","url":"interfaces/_types_.pusherproviderprops.html#wspath","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":25,"kind":1024,"name":"wsPort","url":"interfaces/_types_.pusherproviderprops.html#wsport","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":26,"kind":1024,"name":"wssPort","url":"interfaces/_types_.pusherproviderprops.html#wssport","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":27,"kind":1024,"name":"httpHost","url":"interfaces/_types_.pusherproviderprops.html#httphost","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":28,"kind":1024,"name":"httpPort","url":"interfaces/_types_.pusherproviderprops.html#httpport","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":29,"kind":1024,"name":"httpsPort","url":"interfaces/_types_.pusherproviderprops.html#httpsport","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":30,"kind":256,"name":"useChannelOptions","url":"interfaces/_types_.usechanneloptions.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"types\""},{"id":31,"kind":1024,"name":"skip","url":"interfaces/_types_.usechanneloptions.html#skip","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".useChannelOptions"},{"id":32,"kind":1,"name":"\"PusherProvider\"","url":"modules/_pusherprovider_.html","classes":"tsd-kind-external-module"},{"id":33,"kind":32,"name":"PusherContext","url":"modules/_pusherprovider_.html#pushercontext","classes":"tsd-kind-variable tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"PusherProvider\""},{"id":34,"kind":32,"name":"__PusherContext","url":"modules/_pusherprovider_.html#__pushercontext","classes":"tsd-kind-variable tsd-parent-kind-external-module","parent":"\"PusherProvider\""},{"id":35,"kind":32,"name":"__PusherConsumer","url":"modules/_pusherprovider_.html#__pusherconsumer","classes":"tsd-kind-variable tsd-parent-kind-external-module","parent":"\"PusherProvider\""},{"id":36,"kind":64,"name":"PusherProvider","url":"modules/_pusherprovider_.html#pusherprovider","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"PusherProvider\""},{"id":37,"kind":1,"name":"\"mocks\"","url":"modules/_mocks_.html","classes":"tsd-kind-external-module"},{"id":38,"kind":128,"name":"PusherChannelMock","url":"classes/_mocks_.pusherchannelmock.html","classes":"tsd-kind-class tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"mocks\""},{"id":39,"kind":1024,"name":"callbacks","url":"classes/_mocks_.pusherchannelmock.html#callbacks","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock"},{"id":40,"kind":65536,"name":"__type","url":"classes/_mocks_.pusherchannelmock.html#callbacks.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock.callbacks"},{"id":41,"kind":512,"name":"constructor","url":"classes/_mocks_.pusherchannelmock.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock"},{"id":42,"kind":2048,"name":"bind","url":"classes/_mocks_.pusherchannelmock.html#bind","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock"},{"id":43,"kind":2048,"name":"unbind","url":"classes/_mocks_.pusherchannelmock.html#unbind","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock"},{"id":44,"kind":2048,"name":"emit","url":"classes/_mocks_.pusherchannelmock.html#emit","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock"},{"id":45,"kind":128,"name":"PusherPresenceChannelMock","url":"classes/_mocks_.pusherpresencechannelmock.html","classes":"tsd-kind-class tsd-parent-kind-external-module tsd-has-type-parameter tsd-is-not-exported","parent":"\"mocks\""},{"id":46,"kind":1024,"name":"members","url":"classes/_mocks_.pusherpresencechannelmock.html#members","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":47,"kind":65536,"name":"__type","url":"classes/_mocks_.pusherpresencechannelmock.html#members.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock.members"},{"id":48,"kind":32,"name":"members","url":"classes/_mocks_.pusherpresencechannelmock.html#members.__type-1.members-1","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock.members.__type"},{"id":49,"kind":65536,"name":"__type","url":"classes/_mocks_.pusherpresencechannelmock.html#members.__type-1.members-1.__type-2","classes":"tsd-kind-type-literal tsd-parent-kind-variable tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock.members.__type.members"},{"id":50,"kind":32,"name":"myID","url":"classes/_mocks_.pusherpresencechannelmock.html#members.__type-1.myid","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock.members.__type"},{"id":51,"kind":512,"name":"constructor","url":"classes/_mocks_.pusherpresencechannelmock.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class tsd-is-overwrite tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":52,"kind":1024,"name":"callbacks","url":"classes/_mocks_.pusherpresencechannelmock.html#callbacks","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":53,"kind":65536,"name":"__type","url":"classes/_mocks_.pusherpresencechannelmock.html#callbacks.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock.callbacks"},{"id":54,"kind":2048,"name":"bind","url":"classes/_mocks_.pusherpresencechannelmock.html#bind","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":55,"kind":2048,"name":"unbind","url":"classes/_mocks_.pusherpresencechannelmock.html#unbind","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":56,"kind":2048,"name":"emit","url":"classes/_mocks_.pusherpresencechannelmock.html#emit","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":57,"kind":128,"name":"PusherMock","url":"classes/_mocks_.pushermock.html","classes":"tsd-kind-class tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"mocks\""},{"id":58,"kind":1024,"name":"key","url":"classes/_mocks_.pushermock.html#key","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":59,"kind":1024,"name":"config","url":"classes/_mocks_.pushermock.html#config","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":60,"kind":1024,"name":"channels","url":"classes/_mocks_.pushermock.html#channels","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":61,"kind":65536,"name":"__type","url":"classes/_mocks_.pushermock.html#channels.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"mocks\".PusherMock.channels"},{"id":62,"kind":512,"name":"constructor","url":"classes/_mocks_.pushermock.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":63,"kind":2048,"name":"channel","url":"classes/_mocks_.pushermock.html#channel","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":64,"kind":2048,"name":"subscribe","url":"classes/_mocks_.pushermock.html#subscribe","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":65,"kind":2048,"name":"unsubscribe","url":"classes/_mocks_.pushermock.html#unsubscribe","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":66,"kind":2048,"name":"disconnect","url":"classes/_mocks_.pushermock.html#disconnect","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":67,"kind":1,"name":"\"usePusher\"","url":"modules/_usepusher_.html","classes":"tsd-kind-external-module"},{"id":68,"kind":64,"name":"usePusher","url":"modules/_usepusher_.html#usepusher","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"usePusher\""},{"id":69,"kind":1,"name":"\"useChannel\"","url":"modules/_usechannel_.html","classes":"tsd-kind-external-module"},{"id":70,"kind":64,"name":"useChannel","url":"modules/_usechannel_.html#usechannel","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"useChannel\""},{"id":71,"kind":1,"name":"\"useEvent\"","url":"modules/_useevent_.html","classes":"tsd-kind-external-module"},{"id":72,"kind":64,"name":"useEvent","url":"modules/_useevent_.html#useevent","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"useEvent\""},{"id":73,"kind":1,"name":"\"usePresenceChannel\"","url":"modules/_usepresencechannel_.html","classes":"tsd-kind-external-module"},{"id":74,"kind":64,"name":"usePresenceChannel","url":"modules/_usepresencechannel_.html#usepresencechannel","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"usePresenceChannel\""},{"id":75,"kind":1,"name":"\"useTrigger\"","url":"modules/_usetrigger_.html","classes":"tsd-kind-external-module"},{"id":76,"kind":64,"name":"useTrigger","url":"modules/_usetrigger_.html#usetrigger","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"useTrigger\""}]}; \ No newline at end of file + typedoc.search.data = {"kinds":{"1":"External module","32":"Variable","64":"Function","128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal"},"rows":[{"id":0,"kind":1,"name":"\"types\"","url":"modules/_types_.html","classes":"tsd-kind-external-module"},{"id":1,"kind":256,"name":"PusherContextValues","url":"interfaces/_types_.pushercontextvalues.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"types\""},{"id":2,"kind":1024,"name":"client","url":"interfaces/_types_.pushercontextvalues.html#client","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherContextValues"},{"id":3,"kind":1024,"name":"triggerEndpoint","url":"interfaces/_types_.pushercontextvalues.html#triggerendpoint","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherContextValues"},{"id":4,"kind":256,"name":"PusherProviderProps","url":"interfaces/_types_.pusherproviderprops.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"types\""},{"id":5,"kind":1024,"name":"clientKey","url":"interfaces/_types_.pusherproviderprops.html#clientkey","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherProviderProps"},{"id":6,"kind":1024,"name":"cluster","url":"interfaces/_types_.pusherproviderprops.html#cluster","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-overwrite","parent":"\"types\".PusherProviderProps"},{"id":7,"kind":1024,"name":"authEndpoint","url":"interfaces/_types_.pusherproviderprops.html#authendpoint","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-overwrite","parent":"\"types\".PusherProviderProps"},{"id":8,"kind":1024,"name":"auth","url":"interfaces/_types_.pusherproviderprops.html#auth","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-overwrite","parent":"\"types\".PusherProviderProps"},{"id":9,"kind":1024,"name":"triggerEndpoint","url":"interfaces/_types_.pusherproviderprops.html#triggerendpoint","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherProviderProps"},{"id":10,"kind":1024,"name":"defer","url":"interfaces/_types_.pusherproviderprops.html#defer","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherProviderProps"},{"id":11,"kind":1024,"name":"children","url":"interfaces/_types_.pusherproviderprops.html#children","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherProviderProps"},{"id":12,"kind":1024,"name":"value","url":"interfaces/_types_.pusherproviderprops.html#value","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".PusherProviderProps"},{"id":13,"kind":1024,"name":"forceTLS","url":"interfaces/_types_.pusherproviderprops.html#forcetls","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":14,"kind":1024,"name":"encrypted","url":"interfaces/_types_.pusherproviderprops.html#encrypted","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":15,"kind":1024,"name":"authTransport","url":"interfaces/_types_.pusherproviderprops.html#authtransport","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":16,"kind":1024,"name":"authorizer","url":"interfaces/_types_.pusherproviderprops.html#authorizer","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":17,"kind":1024,"name":"disableStats","url":"interfaces/_types_.pusherproviderprops.html#disablestats","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":18,"kind":1024,"name":"enabledTransports","url":"interfaces/_types_.pusherproviderprops.html#enabledtransports","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":19,"kind":1024,"name":"disabledTransports","url":"interfaces/_types_.pusherproviderprops.html#disabledtransports","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":20,"kind":1024,"name":"ignoreNullOrigin","url":"interfaces/_types_.pusherproviderprops.html#ignorenullorigin","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":21,"kind":1024,"name":"activityTimeout","url":"interfaces/_types_.pusherproviderprops.html#activitytimeout","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":22,"kind":1024,"name":"pongTimeout","url":"interfaces/_types_.pusherproviderprops.html#pongtimeout","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":23,"kind":1024,"name":"wsHost","url":"interfaces/_types_.pusherproviderprops.html#wshost","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":24,"kind":1024,"name":"wsPath","url":"interfaces/_types_.pusherproviderprops.html#wspath","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":25,"kind":1024,"name":"wsPort","url":"interfaces/_types_.pusherproviderprops.html#wsport","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":26,"kind":1024,"name":"wssPort","url":"interfaces/_types_.pusherproviderprops.html#wssport","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":27,"kind":1024,"name":"httpHost","url":"interfaces/_types_.pusherproviderprops.html#httphost","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":28,"kind":1024,"name":"httpPort","url":"interfaces/_types_.pusherproviderprops.html#httpport","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":29,"kind":1024,"name":"httpsPort","url":"interfaces/_types_.pusherproviderprops.html#httpsport","classes":"tsd-kind-property tsd-parent-kind-interface tsd-is-inherited","parent":"\"types\".PusherProviderProps"},{"id":30,"kind":256,"name":"useChannelOptions","url":"interfaces/_types_.usechanneloptions.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"types\""},{"id":31,"kind":1024,"name":"skip","url":"interfaces/_types_.usechanneloptions.html#skip","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"types\".useChannelOptions"},{"id":32,"kind":1,"name":"\"PusherProvider\"","url":"modules/_pusherprovider_.html","classes":"tsd-kind-external-module"},{"id":33,"kind":32,"name":"PusherContext","url":"modules/_pusherprovider_.html#pushercontext","classes":"tsd-kind-variable tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"PusherProvider\""},{"id":34,"kind":32,"name":"__PusherContext","url":"modules/_pusherprovider_.html#__pushercontext","classes":"tsd-kind-variable tsd-parent-kind-external-module","parent":"\"PusherProvider\""},{"id":35,"kind":64,"name":"PusherProvider","url":"modules/_pusherprovider_.html#pusherprovider","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"PusherProvider\""},{"id":36,"kind":1,"name":"\"mocks\"","url":"modules/_mocks_.html","classes":"tsd-kind-external-module"},{"id":37,"kind":128,"name":"PusherChannelMock","url":"classes/_mocks_.pusherchannelmock.html","classes":"tsd-kind-class tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"mocks\""},{"id":38,"kind":1024,"name":"callbacks","url":"classes/_mocks_.pusherchannelmock.html#callbacks","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock"},{"id":39,"kind":65536,"name":"__type","url":"classes/_mocks_.pusherchannelmock.html#callbacks.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock.callbacks"},{"id":40,"kind":512,"name":"constructor","url":"classes/_mocks_.pusherchannelmock.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock"},{"id":41,"kind":2048,"name":"bind","url":"classes/_mocks_.pusherchannelmock.html#bind","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock"},{"id":42,"kind":2048,"name":"unbind","url":"classes/_mocks_.pusherchannelmock.html#unbind","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock"},{"id":43,"kind":2048,"name":"emit","url":"classes/_mocks_.pusherchannelmock.html#emit","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherChannelMock"},{"id":44,"kind":128,"name":"PusherPresenceChannelMock","url":"classes/_mocks_.pusherpresencechannelmock.html","classes":"tsd-kind-class tsd-parent-kind-external-module tsd-has-type-parameter tsd-is-not-exported","parent":"\"mocks\""},{"id":45,"kind":1024,"name":"members","url":"classes/_mocks_.pusherpresencechannelmock.html#members","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":46,"kind":65536,"name":"__type","url":"classes/_mocks_.pusherpresencechannelmock.html#members.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock.members"},{"id":47,"kind":32,"name":"members","url":"classes/_mocks_.pusherpresencechannelmock.html#members.__type-1.members-1","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock.members.__type"},{"id":48,"kind":65536,"name":"__type","url":"classes/_mocks_.pusherpresencechannelmock.html#members.__type-1.members-1.__type-2","classes":"tsd-kind-type-literal tsd-parent-kind-variable tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock.members.__type.members"},{"id":49,"kind":32,"name":"myID","url":"classes/_mocks_.pusherpresencechannelmock.html#members.__type-1.myid","classes":"tsd-kind-variable tsd-parent-kind-type-literal tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock.members.__type"},{"id":50,"kind":512,"name":"constructor","url":"classes/_mocks_.pusherpresencechannelmock.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class tsd-is-overwrite tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":51,"kind":1024,"name":"callbacks","url":"classes/_mocks_.pusherpresencechannelmock.html#callbacks","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":52,"kind":65536,"name":"__type","url":"classes/_mocks_.pusherpresencechannelmock.html#callbacks.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock.callbacks"},{"id":53,"kind":2048,"name":"bind","url":"classes/_mocks_.pusherpresencechannelmock.html#bind","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":54,"kind":2048,"name":"unbind","url":"classes/_mocks_.pusherpresencechannelmock.html#unbind","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":55,"kind":2048,"name":"emit","url":"classes/_mocks_.pusherpresencechannelmock.html#emit","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-not-exported","parent":"\"mocks\".PusherPresenceChannelMock"},{"id":56,"kind":128,"name":"PusherMock","url":"classes/_mocks_.pushermock.html","classes":"tsd-kind-class tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"mocks\""},{"id":57,"kind":1024,"name":"key","url":"classes/_mocks_.pushermock.html#key","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":58,"kind":1024,"name":"config","url":"classes/_mocks_.pushermock.html#config","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":59,"kind":1024,"name":"channels","url":"classes/_mocks_.pushermock.html#channels","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":60,"kind":65536,"name":"__type","url":"classes/_mocks_.pushermock.html#channels.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"mocks\".PusherMock.channels"},{"id":61,"kind":512,"name":"constructor","url":"classes/_mocks_.pushermock.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":62,"kind":2048,"name":"channel","url":"classes/_mocks_.pushermock.html#channel","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":63,"kind":2048,"name":"subscribe","url":"classes/_mocks_.pushermock.html#subscribe","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":64,"kind":2048,"name":"unsubscribe","url":"classes/_mocks_.pushermock.html#unsubscribe","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":65,"kind":2048,"name":"disconnect","url":"classes/_mocks_.pushermock.html#disconnect","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-not-exported","parent":"\"mocks\".PusherMock"},{"id":66,"kind":1,"name":"\"usePusher\"","url":"modules/_usepusher_.html","classes":"tsd-kind-external-module"},{"id":67,"kind":64,"name":"usePusher","url":"modules/_usepusher_.html#usepusher","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"usePusher\""},{"id":68,"kind":1,"name":"\"useChannel\"","url":"modules/_usechannel_.html","classes":"tsd-kind-external-module"},{"id":69,"kind":64,"name":"useChannel","url":"modules/_usechannel_.html#usechannel","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"useChannel\""},{"id":70,"kind":1,"name":"\"useEvent\"","url":"modules/_useevent_.html","classes":"tsd-kind-external-module"},{"id":71,"kind":64,"name":"useEvent","url":"modules/_useevent_.html#useevent","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"useEvent\""},{"id":72,"kind":1,"name":"\"usePresenceChannel\"","url":"modules/_usepresencechannel_.html","classes":"tsd-kind-external-module"},{"id":73,"kind":64,"name":"usePresenceChannel","url":"modules/_usepresencechannel_.html#usepresencechannel","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"usePresenceChannel\""},{"id":74,"kind":1,"name":"\"useTrigger\"","url":"modules/_usetrigger_.html","classes":"tsd-kind-external-module"},{"id":75,"kind":64,"name":"useTrigger","url":"modules/_usetrigger_.html#usetrigger","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"useTrigger\""}]}; \ No newline at end of file diff --git a/docs/classes/_mocks_.pusherchannelmock.html b/docs/classes/_mocks_.pusherchannelmock.html index 0c9853c..43afb37 100644 --- a/docs/classes/_mocks_.pusherchannelmock.html +++ b/docs/classes/_mocks_.pusherchannelmock.html @@ -121,7 +121,7 @@

constructor

  • Returns PusherChannelMock

    @@ -137,7 +137,7 @@

    callbacks

    callbacks: object
    @@ -167,7 +167,7 @@

    bind

  • @@ -204,7 +204,7 @@

    emit

  • @@ -241,7 +241,7 @@

    unbind

  • diff --git a/docs/classes/_mocks_.pushermock.html b/docs/classes/_mocks_.pushermock.html index 90ce9b6..c39ea5b 100644 --- a/docs/classes/_mocks_.pushermock.html +++ b/docs/classes/_mocks_.pushermock.html @@ -119,7 +119,7 @@

    constructor

  • @@ -149,7 +149,7 @@

    channels

    channels: object
    @@ -167,7 +167,7 @@

    config

    config: Config
    @@ -177,7 +177,7 @@

    key

    key: string
    @@ -194,7 +194,7 @@

    channel

  • @@ -226,7 +226,7 @@

    disconnect

  • Returns void

    @@ -243,7 +243,7 @@

    subscribe

  • @@ -275,7 +275,7 @@

    unsubscribe

  • diff --git a/docs/classes/_mocks_.pusherpresencechannelmock.html b/docs/classes/_mocks_.pusherpresencechannelmock.html index c81d1b1..e2212fa 100644 --- a/docs/classes/_mocks_.pusherpresencechannelmock.html +++ b/docs/classes/_mocks_.pusherpresencechannelmock.html @@ -131,7 +131,7 @@

    constructor

    Returns PusherPresenceChannelMock

    @@ -148,7 +148,7 @@

    callbacks

    @@ -171,7 +171,7 @@

    members

    members: object
    @@ -205,7 +205,7 @@

    bind

    @@ -243,7 +243,7 @@

    emit

    @@ -281,7 +281,7 @@

    unbind

    diff --git a/docs/index.html b/docs/index.html index 0e06c33..2b5c95e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -70,7 +70,7 @@

    use-pusher

    Easy as hooks that integrate with the pusher-js library.

    -

    NPM JavaScript Style Guide

    +

    NPM Typed

    API Reference/Docs
    @@ -158,7 +158,7 @@

    useEvent

    useTrigger

    A helper function to create a server triggered event. BYO server (See Trigger Server below). Pass in triggerEndpoint prop to <PusherProvider />. Any auth headers from config.auth.headers automatically get passed to the fetch call.

    -
    import {useTrigger} from 'use-pusher`;
    +				
    import {useTrigger} from 'use-pusher';
     
     const Example = () => {.
       const trigger = useTrigger();
    @@ -218,6 +218,51 @@ 

    Trigger Server

    Typescript

    This project was built using typescript, so types are built-in. Yeeeew!

    + +

    Testing

    +
    +

    Typed PusherMock, PusherChannelMock and PusherPresenceChannelMock utils are provided based on pusher-js-mock (thanks mate 🙏). Use these to stub out the client and channels, with an additional emit method on the channel classes.

    +

    Testing emitted events with jest can be achieved using jest.mock and react-testing-library (or enzyme, though your tests should reflect what the user should see NOT how the component handles events internally):

    +
    // Example.tsx
    +import React from "react";
    +import { useChannel, useEvent } from "use-pusher";
    +
    +const Example = () => {
    +  const [title, setTitle] = useState();
    +  const channel = useChannel("my-channel");
    +  useEvent(channel, "title", ({ data }) => setTitle(data));
    +
    +  return <span>{title}</span>;
    +};
    +
    +// Example.test.tsx
    +import { render, act } from "@testing-library/react";
    +import { PusherMock, PusherChannelMock } from "use-pusher";
    +
    +// mock out the result of the useChannel hook
    +const mockChannel = new PusherChannelMock();
    +jest.mock("use-pusher", () => ({
    +  ...require.requireActual("use-pusher"),
    +  useChannel: () => mockChannel
    +}));
    +
    +test("should show a title when it receives a title event", async () => {
    +  // mock the client
    +  const client = { current: new PusherMock("client-key", { cluster: "ap4" }) };
    +
    +  // render component and provider with a mocked context value
    +  const { findByText } = render(
    +    <PusherProvider clientKey="client-key" cluster="ap4" value={{ client }}>
    +      <Example />
    +    </PusherProvider>
    +  );
    +
    +  // emit an event on the mocked channel
    +  act(() => mockChannel.emit("title", { data: "Hello world" }));
    +
    +  // assert expectations
    +  expect(await findByText("Hello world")).toBeInTheDocument();
    +});

    Contributing

    diff --git a/docs/interfaces/_types_.pushercontextvalues.html b/docs/interfaces/_types_.pushercontextvalues.html index b65330a..af91332 100644 --- a/docs/interfaces/_types_.pushercontextvalues.html +++ b/docs/interfaces/_types_.pushercontextvalues.html @@ -85,7 +85,6 @@

    Index

    Properties

    @@ -100,17 +99,7 @@

    Optional client

    client: any | undefined
    - -
    - -

    Optional pusherOptions

    -
    pusherOptions: Config
    -
    @@ -120,7 +109,7 @@

    Optional triggerEndpoint<
    triggerEndpoint: undefined | string
    @@ -168,9 +157,6 @@

    Optional triggerEndpoint<
  • client
  • -
  • - pusherOptions -
  • triggerEndpoint
  • diff --git a/docs/interfaces/_types_.pusherproviderprops.html b/docs/interfaces/_types_.pusherproviderprops.html index 02debb9..7e6e989 100644 --- a/docs/interfaces/_types_.pusherproviderprops.html +++ b/docs/interfaces/_types_.pusherproviderprops.html @@ -109,6 +109,7 @@

    Properties

  • ignoreNullOrigin
  • pongTimeout
  • triggerEndpoint
  • +
  • value
  • wsHost
  • wsPath
  • wsPort
  • @@ -145,7 +146,7 @@

    Optional auth

    @@ -156,7 +157,7 @@

    Optional authEndpoint

    Overrides Config.authEndpoint

    @@ -199,7 +200,7 @@

    children

    children: React.ReactNode
    @@ -209,7 +210,7 @@

    clientKey

    clientKey: string
    @@ -220,7 +221,7 @@

    cluster

    @@ -230,7 +231,7 @@

    Optional defer

    defer: undefined | false | true
    @@ -397,7 +398,17 @@

    Optional triggerEndpoint<
    triggerEndpoint: undefined | string
    + +
    + +

    Optional value

    +
    value: any
    +
    @@ -549,6 +560,9 @@

    Optional wssPort

  • triggerEndpoint
  • +
  • + value +
  • wsHost
  • diff --git a/docs/interfaces/_types_.usechanneloptions.html b/docs/interfaces/_types_.usechanneloptions.html index f924958..c65dd26 100644 --- a/docs/interfaces/_types_.usechanneloptions.html +++ b/docs/interfaces/_types_.usechanneloptions.html @@ -98,7 +98,7 @@

    Optional skip

    skip: undefined | false | true
    diff --git a/docs/modules/_pusherprovider_.html b/docs/modules/_pusherprovider_.html index 43125d1..a3e6e80 100644 --- a/docs/modules/_pusherprovider_.html +++ b/docs/modules/_pusherprovider_.html @@ -74,7 +74,6 @@

    Index

    Variables

    @@ -95,17 +94,7 @@

    Const PusherContext

    PusherContext: Context<PusherContextValues> = React.createContext<PusherContextValues>({})
    - -
    - -

    Const __PusherConsumer

    -
    __PusherConsumer: ExoticComponent<ConsumerProps<PusherContextValues>> = PusherContext.Consumer
    -
    @@ -115,7 +104,7 @@

    Const __PusherContext__PusherContext: Context<PusherContextValues> = PusherContext

    @@ -132,7 +121,7 @@

    PusherProvider

  • @@ -215,9 +204,6 @@

    Returns Element PusherContext

  • -
  • - __PusherConsumer -
  • __PusherContext
  • diff --git a/docs/modules/_usechannel_.html b/docs/modules/_usechannel_.html index f50ec7d..f235d64 100644 --- a/docs/modules/_usechannel_.html +++ b/docs/modules/_usechannel_.html @@ -91,7 +91,7 @@

    useChannel

  • diff --git a/docs/modules/_useevent_.html b/docs/modules/_useevent_.html index 623169e..eeaf734 100644 --- a/docs/modules/_useevent_.html +++ b/docs/modules/_useevent_.html @@ -91,7 +91,7 @@

    useEvent

  • diff --git a/docs/modules/_usepresencechannel_.html b/docs/modules/_usepresencechannel_.html index 9415234..3d237f2 100644 --- a/docs/modules/_usepresencechannel_.html +++ b/docs/modules/_usepresencechannel_.html @@ -91,7 +91,7 @@

    usePresenceChannel

  • diff --git a/docs/modules/_usepusher_.html b/docs/modules/_usepusher_.html index 3562512..68ace21 100644 --- a/docs/modules/_usepusher_.html +++ b/docs/modules/_usepusher_.html @@ -91,7 +91,7 @@

    usePusher

  • diff --git a/docs/modules/_usetrigger_.html b/docs/modules/_usetrigger_.html index a192e30..8c87f8c 100644 --- a/docs/modules/_usetrigger_.html +++ b/docs/modules/_usetrigger_.html @@ -91,7 +91,7 @@

    useTrigger

  • diff --git a/src/__tests__/Example.tsx b/src/__tests__/Example.tsx new file mode 100644 index 0000000..1da707d --- /dev/null +++ b/src/__tests__/Example.tsx @@ -0,0 +1,43 @@ +// example.tsx +import React, { useState } from "react"; +import { render, act } from "@testing-library/react"; +import { + PusherProvider, + useChannel, + useEvent, + PusherMock, + PusherChannelMock +} from "../"; + +// Example component +const Example = () => { + const [title, setTitle] = useState(); + const channel = useChannel("my-channel"); + useEvent(channel, "title", ({ data }) => setTitle(data)); + + return {title}; +}; + +// mock out the result of the useChannel hook +const mockChannel = new PusherChannelMock(); +jest.mock("../", () => ({ + ...require.requireActual("../"), + useChannel: () => mockChannel +})); + +test("should show a title when it receives a title event from the socket.", async () => { + // render the provider with a mocked context value + const clientKey = "key"; + const options = { cluster: "ap4" }; + const client = { current: new PusherMock(clientKey, options) }; + const { findByText } = render( + + + + ); + // call an event on the mocked channel + act(() => mockChannel.emit("title", { data: "Hello world" })); + + // assert expectations + expect(await findByText("Hello world")).toBeTruthy(); +}); diff --git a/src/__tests__/useEvent.tsx b/src/__tests__/useEvent.tsx index 7774ff2..25aed97 100644 --- a/src/__tests__/useEvent.tsx +++ b/src/__tests__/useEvent.tsx @@ -50,7 +50,7 @@ describe("useEvent hook", () => { setup(undefined, "my-event", () => {}); expect(global.console.warn).toHaveBeenCalledWith( - "No channel supplied to onEvent." + "No channel supplied to onEvent. Not binding callback." ); }); diff --git a/src/useEvent.ts b/src/useEvent.ts index d899671..41aec59 100644 --- a/src/useEvent.ts +++ b/src/useEvent.ts @@ -21,7 +21,7 @@ export function useEvent( const callbackRef = useCallback(callback, dependencies); useEffect(() => { if (channel === undefined) { - console.warn("No channel supplied to onEvent."); + console.warn("No channel supplied to onEvent. Not binding callback."); return; } channel.bind(eventName, callbackRef);