@@ -106,7 +106,7 @@ describe("parser", () => {
106
106
) ;
107
107
} ) ;
108
108
109
- it ( "throws an error when encoding circular objects" , ( ) => {
109
+ it ( "does not throw an error when encoding circular objects" , ( ) => {
110
110
const a = { } ;
111
111
a . b = a ;
112
112
@@ -119,7 +119,7 @@ describe("parser", () => {
119
119
120
120
const encoder = new Encoder ( ) ;
121
121
122
- expect ( ( ) => encoder . encode ( data ) ) . to . throwException ( ) ;
122
+ expect ( ( ) => encoder . encode ( data ) ) . not . to . throwException ( ) ;
123
123
} ) ;
124
124
125
125
it ( "decodes a bad binary packet" , ( ) => {
@@ -147,4 +147,28 @@ describe("parser", () => {
147
147
/ ^ u n k n o w n p a c k e t t y p e 9 $ /
148
148
) ;
149
149
} ) ;
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
+ } ) ;
150
174
} ) ;
0 commit comments