Skip to content

Commit

Permalink
Merge pull request #35 from kubk/patch-1
Browse files Browse the repository at this point in the history
Add unbind_all() method
  • Loading branch information
nikolalsvk authored Feb 22, 2021
2 parents fd8206e + 88ac3e7 commit aa8ce51
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/__tests__/pusher-channel-mock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
7 changes: 7 additions & 0 deletions src/pusher-channel-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit aa8ce51

Please sign in to comment.