Skip to content

Commit b66a1ed

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

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/parser.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe("socket.io-parser", () => {
8282
});
8383
});
8484

85-
it("throws an error when encoding circular objects", () => {
85+
it("does not throw an error when encoding circular objects", () => {
8686
const a = {};
8787
a.b = a;
8888

@@ -95,7 +95,7 @@ describe("socket.io-parser", () => {
9595

9696
const encoder = new Encoder();
9797

98-
expect(() => encoder.encode(data)).to.throwException();
98+
expect(() => encoder.encode(data)).not.to.throwException();
9999
});
100100

101101
it("decodes a bad binary packet", () => {
@@ -127,4 +127,28 @@ describe("socket.io-parser", () => {
127127
/^Unknown type: 999$/
128128
);
129129
});
130+
131+
it("correctly encodes and decodes circular data in array", (done) => {
132+
const circularObj = {};
133+
134+
circularObj.circularArray = [circularObj, circularObj];
135+
136+
const obj = {
137+
type: PacketType.EVENT,
138+
data: ["a", circularObj],
139+
id: 1,
140+
nsp: "/",
141+
};
142+
143+
const encoder = new Encoder();
144+
const decoder = new Decoder();
145+
146+
decoder.on("decoded", (packet) => {
147+
expect(packet.data[1] === packet.data[1].circularArray[0]).to.be.true;
148+
expect(packet.data[1] === packet.data[1].circularArray[1]).to.be.true;
149+
done();
150+
});
151+
152+
encoder.encode(obj).forEach((packet) => decoder.add(packet));
153+
});
130154
});

0 commit comments

Comments
 (0)