diff --git a/src/__tests__/pusher-channel-mock.spec.ts b/src/__tests__/pusher-channel-mock.spec.ts index 5b356f4..b02980f 100644 --- a/src/__tests__/pusher-channel-mock.spec.ts +++ b/src/__tests__/pusher-channel-mock.spec.ts @@ -21,6 +21,23 @@ describe("PusherChannelMock", () => { }); }); + describe("#unbind_all", () => { + it("clears events from all the callbacks", () => { + const firstCallback = jest.fn(); + const secondCallback = jest.fn(); + channelMock.bind("first-channel", firstCallback); + channelMock.bind("second-channel", secondCallback); + + channelMock.unbind_all(); + channelMock.emit("first-channel"); + channelMock.emit("second-channel"); + + expect(firstCallback).not.toHaveBeenCalled(); + expect(secondCallback).not.toHaveBeenCalled(); + expect(channelMock.callbacks).toEqual({}); + }); + }); + describe("#unbind", () => { describe("with callbacks defined for the event", () => { it("removes name: callback from callbacks object", () => { diff --git a/src/pusher-channel-mock.ts b/src/pusher-channel-mock.ts index 92bfa4a..5cdd434 100644 --- a/src/pusher-channel-mock.ts +++ b/src/pusher-channel-mock.ts @@ -36,6 +36,13 @@ class PusherChannelMock { ); } + /** + * Unbind callbacks from all the events. + */ + public unbind_all() { + this.callbacks = {}; + } + /** * Emit event with data. * @param {String} name - name of the event.