-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmocks.ts
37 lines (33 loc) · 873 Bytes
/
mocks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Config } from "pusher-js";
export class ChannelMock {
binding: any = {
eventType: undefined,
onEvent: undefined
};
emit = jest.fn((eventName: string, data: any) => {
if (
this.binding.onEvent !== undefined &&
this.binding.eventType === eventName
) {
this.binding.onEvent(data);
}
});
bind = jest.fn((eventName: string, onEvent: any) => {
this.binding.onEvent = onEvent;
this.binding.eventType = eventName;
});
unbind = jest.fn(() => {
this.binding.onEvent = undefined;
this.binding.eventType = undefined;
});
}
export class PusherMock {
clientKey: undefined | string;
config: undefined | Config;
constructor(clientKey: string, config: Config) {
this.config = config;
this.clientKey = clientKey;
}
subscribe = jest.fn(() => new ChannelMock());
unsubscribe = jest.fn();
}