-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathdisconnect.js
More file actions
85 lines (66 loc) · 2.21 KB
/
Copy pathdisconnect.js
File metadata and controls
85 lines (66 loc) · 2.21 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { jest } from "@jest/globals";
import { xml } from "@xmpp/test";
import Connection from "../index.js";
test("disconnect", async () => {
const conn = new Connection();
const el = {};
const spy_closeStream = jest
.spyOn(conn, "_closeStream")
.mockImplementation(async () => el);
const spy_closeSocket = jest.spyOn(conn, "_closeSocket");
expect(await conn.disconnect()).toBe(el);
expect(spy_closeStream).toHaveBeenCalledTimes(1);
expect(spy_closeSocket).toHaveBeenCalledTimes(1);
});
test("disconnect with _closeStream rejection", async () => {
const conn = new Connection();
const spy_closeStream = jest
.spyOn(conn, "_closeStream")
.mockImplementation(() => {
return Promise.reject();
});
const spy_closeSocket = jest.spyOn(conn, "_closeSocket");
await conn.disconnect();
expect(spy_closeStream).toHaveBeenCalledTimes(1);
expect(spy_closeSocket).toHaveBeenCalledTimes(1);
});
test("disconnect with _closeSocket rejection", async () => {
const conn = new Connection();
const spy_closeStream = jest.spyOn(conn, "_closeStream");
const spy_closeSocket = jest
.spyOn(conn, "_closeSocket")
.mockImplementation(() => {
return Promise.reject();
});
await conn.disconnect();
expect(spy_closeStream).toHaveBeenCalledTimes(1);
expect(spy_closeSocket).toHaveBeenCalledTimes(1);
});
test("disconnect with _closeStream and _closeSocket rejections", async () => {
const conn = new Connection();
const spy_closeStream = jest
.spyOn(conn, "_closeStream")
.mockImplementation(() => {
return Promise.reject();
});
const spy_closeSocket = jest
.spyOn(conn, "_closeSocket")
.mockImplementation(() => {
return Promise.reject();
});
await conn.disconnect();
expect(spy_closeStream).toHaveBeenCalledTimes(1);
expect(spy_closeSocket).toHaveBeenCalledTimes(1);
});
test("resolves if socket property is undefined", async () => {
const conn = new Connection();
conn.footerElement = () => xml("foo");
conn.socket = undefined;
await conn.disconnect();
expect().pass();
});
test("does not reject if connection is not established", async () => {
const conn = new Connection();
await conn.disconnect();
expect().pass();
});