@@ -82,7 +82,7 @@ describe("socket.io-parser", () => {
82
82
} ) ;
83
83
} ) ;
84
84
85
- it ( "throws an error when encoding circular objects" , ( ) => {
85
+ it ( "does not throw an error when encoding circular objects" , ( ) => {
86
86
const a = { } ;
87
87
a . b = a ;
88
88
@@ -95,7 +95,7 @@ describe("socket.io-parser", () => {
95
95
96
96
const encoder = new Encoder ( ) ;
97
97
98
- expect ( ( ) => encoder . encode ( data ) ) . to . throwException ( ) ;
98
+ expect ( ( ) => encoder . encode ( data ) ) . not . to . throwException ( ) ;
99
99
} ) ;
100
100
101
101
it ( "decodes a bad binary packet" , ( ) => {
@@ -127,4 +127,28 @@ describe("socket.io-parser", () => {
127
127
/ ^ U n k n o w n t y p e : 9 9 9 $ /
128
128
) ;
129
129
} ) ;
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
+ } ) ;
130
154
} ) ;
0 commit comments