Skip to content

Commit b01c71c

Browse files
committed
feat: update existing circular test case and add new one
1 parent 1466381 commit b01c71c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/parser.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe("parser", () => {
106106
);
107107
});
108108

109-
it("throws an error when encoding circular objects", () => {
109+
it("does not throw an error when encoding circular objects", () => {
110110
const a = {};
111111
a.b = a;
112112

@@ -119,7 +119,7 @@ describe("parser", () => {
119119

120120
const encoder = new Encoder();
121121

122-
expect(() => encoder.encode(data)).to.throwException();
122+
expect(() => encoder.encode(data)).not.to.throwException();
123123
});
124124

125125
it("decodes a bad binary packet", () => {
@@ -147,4 +147,28 @@ describe("parser", () => {
147147
/^unknown packet type 9$/
148148
);
149149
});
150+
151+
it("correctly encodes and decodes circular data in array", (done) => {
152+
const circularObj = {};
153+
154+
circularObj.circularArray = [circularObj, circularObj];
155+
156+
const obj = {
157+
type: PacketType.EVENT,
158+
data: ["a", circularObj],
159+
id: 1,
160+
nsp: "/",
161+
};
162+
163+
const encoder = new Encoder();
164+
const decoder = new Decoder();
165+
166+
decoder.on("decoded", (packet) => {
167+
expect(packet.data[1] === packet.data[1].circularArray[0]).to.be.true;
168+
expect(packet.data[1] === packet.data[1].circularArray[1]).to.be.true;
169+
done();
170+
});
171+
172+
encoder.encode(obj).forEach((packet) => decoder.add(packet));
173+
});
150174
});

0 commit comments

Comments
 (0)