@@ -100,28 +100,47 @@ describe('WebSocket', () => {
100
100
Object . keys ( readyStates ) . forEach ( ( state ) => {
101
101
describe ( `\`${ state } \`` , ( ) => {
102
102
it ( 'is enumerable property of class' , ( ) => {
103
- const propertyDescripter = Object . getOwnPropertyDescriptor (
104
- WebSocket ,
105
- state
106
- ) ;
103
+ const descriptor = Object . getOwnPropertyDescriptor ( WebSocket , state ) ;
107
104
108
- assert . strictEqual ( propertyDescripter . value , readyStates [ state ] ) ;
109
- assert . strictEqual ( propertyDescripter . enumerable , true ) ;
105
+ assert . deepStrictEqual ( descriptor , {
106
+ configurable : false ,
107
+ enumerable : true ,
108
+ value : readyStates [ state ] ,
109
+ writable : false
110
+ } ) ;
110
111
} ) ;
111
112
112
- it ( 'is property of instance' , ( ) => {
113
- const ws = new WebSocket ( 'ws://localhost' , {
114
- agent : new CustomAgent ( )
115
- } ) ;
113
+ it ( 'is enumerable property of prototype' , ( ) => {
114
+ const descriptor = Object . getOwnPropertyDescriptor (
115
+ WebSocket . prototype ,
116
+ state
117
+ ) ;
116
118
117
- assert . strictEqual ( ws [ state ] , readyStates [ state ] ) ;
119
+ assert . deepStrictEqual ( descriptor , {
120
+ configurable : false ,
121
+ enumerable : true ,
122
+ value : readyStates [ state ] ,
123
+ writable : false
124
+ } ) ;
118
125
} ) ;
119
126
} ) ;
120
127
} ) ;
121
128
} ) ;
122
129
123
130
describe ( 'Attributes' , ( ) => {
124
131
describe ( '`binaryType`' , ( ) => {
132
+ it ( 'is enumerable and configurable' , ( ) => {
133
+ const descriptor = Object . getOwnPropertyDescriptor (
134
+ WebSocket . prototype ,
135
+ 'binaryType'
136
+ ) ;
137
+
138
+ assert . strictEqual ( descriptor . configurable , true ) ;
139
+ assert . strictEqual ( descriptor . enumerable , true ) ;
140
+ assert . ok ( descriptor . get !== undefined ) ;
141
+ assert . ok ( descriptor . set !== undefined ) ;
142
+ } ) ;
143
+
125
144
it ( "defaults to 'nodebuffer'" , ( ) => {
126
145
const ws = new WebSocket ( 'ws://localhost' , {
127
146
agent : new CustomAgent ( )
@@ -153,6 +172,18 @@ describe('WebSocket', () => {
153
172
} ) ;
154
173
155
174
describe ( '`bufferedAmount`' , ( ) => {
175
+ it ( 'is enumerable and configurable' , ( ) => {
176
+ const descriptor = Object . getOwnPropertyDescriptor (
177
+ WebSocket . prototype ,
178
+ 'bufferedAmount'
179
+ ) ;
180
+
181
+ assert . strictEqual ( descriptor . configurable , true ) ;
182
+ assert . strictEqual ( descriptor . enumerable , true ) ;
183
+ assert . ok ( descriptor . get !== undefined ) ;
184
+ assert . ok ( descriptor . set === undefined ) ;
185
+ } ) ;
186
+
156
187
it ( 'defaults to zero' , ( ) => {
157
188
const ws = new WebSocket ( 'ws://localhost' , {
158
189
agent : new CustomAgent ( )
@@ -225,6 +256,18 @@ describe('WebSocket', () => {
225
256
} ) ;
226
257
227
258
describe ( '`extensions`' , ( ) => {
259
+ it ( 'is enumerable and configurable' , ( ) => {
260
+ const descriptor = Object . getOwnPropertyDescriptor (
261
+ WebSocket . prototype ,
262
+ 'bufferedAmount'
263
+ ) ;
264
+
265
+ assert . strictEqual ( descriptor . configurable , true ) ;
266
+ assert . strictEqual ( descriptor . enumerable , true ) ;
267
+ assert . ok ( descriptor . get !== undefined ) ;
268
+ assert . ok ( descriptor . set === undefined ) ;
269
+ } ) ;
270
+
228
271
it ( 'exposes the negotiated extensions names (1/2)' , ( done ) => {
229
272
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
230
273
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
@@ -269,6 +312,18 @@ describe('WebSocket', () => {
269
312
} ) ;
270
313
271
314
describe ( '`protocol`' , ( ) => {
315
+ it ( 'is enumerable and configurable' , ( ) => {
316
+ const descriptor = Object . getOwnPropertyDescriptor (
317
+ WebSocket . prototype ,
318
+ 'protocol'
319
+ ) ;
320
+
321
+ assert . strictEqual ( descriptor . configurable , true ) ;
322
+ assert . strictEqual ( descriptor . enumerable , true ) ;
323
+ assert . ok ( descriptor . get !== undefined ) ;
324
+ assert . ok ( descriptor . set === undefined ) ;
325
+ } ) ;
326
+
272
327
it ( 'exposes the subprotocol selected by the server' , ( done ) => {
273
328
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
274
329
const port = wss . address ( ) . port ;
@@ -290,6 +345,18 @@ describe('WebSocket', () => {
290
345
} ) ;
291
346
292
347
describe ( '`readyState`' , ( ) => {
348
+ it ( 'is enumerable and configurable' , ( ) => {
349
+ const descriptor = Object . getOwnPropertyDescriptor (
350
+ WebSocket . prototype ,
351
+ 'readyState'
352
+ ) ;
353
+
354
+ assert . strictEqual ( descriptor . configurable , true ) ;
355
+ assert . strictEqual ( descriptor . enumerable , true ) ;
356
+ assert . ok ( descriptor . get !== undefined ) ;
357
+ assert . ok ( descriptor . set === undefined ) ;
358
+ } ) ;
359
+
293
360
it ( 'defaults to `CONNECTING`' , ( ) => {
294
361
const ws = new WebSocket ( 'ws://localhost' , {
295
362
agent : new CustomAgent ( )
@@ -339,6 +406,18 @@ describe('WebSocket', () => {
339
406
} ) ;
340
407
341
408
describe ( '`url`' , ( ) => {
409
+ it ( 'is enumerable and configurable' , ( ) => {
410
+ const descriptor = Object . getOwnPropertyDescriptor (
411
+ WebSocket . prototype ,
412
+ 'url'
413
+ ) ;
414
+
415
+ assert . strictEqual ( descriptor . configurable , true ) ;
416
+ assert . strictEqual ( descriptor . enumerable , true ) ;
417
+ assert . ok ( descriptor . get !== undefined ) ;
418
+ assert . ok ( descriptor . set === undefined ) ;
419
+ } ) ;
420
+
342
421
it ( 'exposes the server url' , ( ) => {
343
422
const url = 'ws://localhost' ;
344
423
const ws = new WebSocket ( url , { agent : new CustomAgent ( ) } ) ;
@@ -1729,6 +1808,18 @@ describe('WebSocket', () => {
1729
1808
1730
1809
describe ( 'WHATWG API emulation' , ( ) => {
1731
1810
it ( 'supports the `on{close,error,message,open}` attributes' , ( ) => {
1811
+ for ( const property of [ 'onclose' , 'onerror' , 'onmessage' , 'onopen' ] ) {
1812
+ const descriptor = Object . getOwnPropertyDescriptor (
1813
+ WebSocket . prototype ,
1814
+ property
1815
+ ) ;
1816
+
1817
+ assert . strictEqual ( descriptor . configurable , true ) ;
1818
+ assert . strictEqual ( descriptor . enumerable , true ) ;
1819
+ assert . ok ( descriptor . get !== undefined ) ;
1820
+ assert . ok ( descriptor . set !== undefined ) ;
1821
+ }
1822
+
1732
1823
const ws = new WebSocket ( 'ws://localhost' , { agent : new CustomAgent ( ) } ) ;
1733
1824
1734
1825
assert . strictEqual ( ws . onmessage , undefined ) ;
0 commit comments