-
Notifications
You must be signed in to change notification settings - Fork 378
/
Copy pathtest.js
36 lines (29 loc) · 985 Bytes
/
test.js
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
import _reconnect from "./index.js";
import Connection from "@xmpp/connection";
test("schedules a reconnect when disconnect is emitted", () => {
const entity = new Connection();
const reconnect = _reconnect({ entity });
const spy_scheduleReconnect = jest.spyOn(reconnect, "scheduleReconnect");
expect(spy_scheduleReconnect).toHaveBeenCalledTimes(0);
entity.emit("disconnect");
expect(spy_scheduleReconnect).toHaveBeenCalledTimes(1);
});
test("#reconnect", async () => {
const service = "service";
const lang = "lang";
const domain = "domain";
const entity = new Connection({
service,
lang,
domain,
});
const reconnect = _reconnect({ entity });
const spy_connect = jest.spyOn(entity, "connect").mockResolvedValue();
const spy_open = jest.spyOn(entity, "open").mockResolvedValue();
await reconnect.reconnect();
expect(spy_connect).toHaveBeenCalledWith(service);
expect(spy_open).toHaveBeenCalledWith({
domain,
lang,
});
});