Skip to content

Commit

Permalink
feat: update existing circular test case and add new one
Browse files Browse the repository at this point in the history
  • Loading branch information
ayan4m1 committed Aug 21, 2021
1 parent 1466381 commit b01c71c
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("parser", () => {
);
});

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

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

const encoder = new Encoder();

expect(() => encoder.encode(data)).to.throwException();
expect(() => encoder.encode(data)).not.to.throwException();
});

it("decodes a bad binary packet", () => {
Expand Down Expand Up @@ -147,4 +147,28 @@ describe("parser", () => {
/^unknown packet type 9$/
);
});

it("correctly encodes and decodes circular data in array", (done) => {
const circularObj = {};

circularObj.circularArray = [circularObj, circularObj];

const obj = {
type: PacketType.EVENT,
data: ["a", circularObj],
id: 1,
nsp: "/",
};

const encoder = new Encoder();
const decoder = new Decoder();

decoder.on("decoded", (packet) => {
expect(packet.data[1] === packet.data[1].circularArray[0]).to.be.true;
expect(packet.data[1] === packet.data[1].circularArray[1]).to.be.true;
done();
});

encoder.encode(obj).forEach((packet) => decoder.add(packet));
});
});

0 comments on commit b01c71c

Please sign in to comment.