1- /* eslint no-unused-expressions: "off" */
1+ 'use strict'
22
3+ const assert = require ( 'node:assert' )
4+ const { describe, it } = require ( 'node:test' )
35const { format } = require ( 'node:util' )
4- const chai = require ( 'chai' )
5- const chaiIterator = require ( 'chai-iterator' )
6- const { Headers } = require ( '../../lib/fetch/headers.js' )
7-
8- chai . use ( chaiIterator )
9-
10- const { expect } = chai
6+ const { Headers } = require ( '../../index.js' )
117
128describe ( 'Headers' , ( ) => {
139 it ( 'should have attributes conforming to Web IDL' , ( ) => {
1410 const headers = new Headers ( )
15- expect ( Object . getOwnPropertyNames ( headers ) ) . to . be . empty
11+ assert . strictEqual ( Object . getOwnPropertyNames ( headers ) . length , 0 )
1612 const enumerableProperties = [ ]
1713
1814 for ( const property in headers ) {
@@ -30,7 +26,7 @@ describe('Headers', () => {
3026 'set' ,
3127 'values'
3228 ] ) {
33- expect ( enumerableProperties ) . to . contain ( toCheck )
29+ assert . strictEqual ( enumerableProperties . includes ( toCheck ) , true )
3430 }
3531 } )
3632
@@ -41,14 +37,14 @@ describe('Headers', () => {
4137 [ 'b' , '3' ] ,
4238 [ 'a' , '1' ]
4339 ] )
44- expect ( headers ) . to . have . property ( ' forEach')
40+ assert . strictEqual ( typeof headers . forEach , 'function ')
4541
4642 const result = [ ]
4743 for ( const [ key , value ] of headers . entries ( ) ) {
4844 result . push ( [ key , value ] )
4945 }
5046
51- expect ( result ) . to . deep . equal ( [
47+ assert . deepStrictEqual ( result , [
5248 [ 'a' , '1' ] ,
5349 [ 'b' , '2, 3' ] ,
5450 [ 'c' , '4' ]
@@ -66,23 +62,23 @@ describe('Headers', () => {
6662 results . push ( { value, key, object } )
6763 } )
6864
69- expect ( results . length ) . to . equal ( 2 )
70- expect ( { key : 'accept' , value : 'application/json, text/plain' , object : headers } ) . to . deep . equal ( results [ 0 ] )
71- expect ( { key : 'content-type' , value : 'text/html' , object : headers } ) . to . deep . equal ( results [ 1 ] )
65+ assert . strictEqual ( results . length , 2 )
66+ assert . deepStrictEqual ( results [ 0 ] , { key : 'accept' , value : 'application/json, text/plain' , object : headers } )
67+ assert . deepStrictEqual ( results [ 1 ] , { key : 'content-type' , value : 'text/html' , object : headers } )
7268 } )
7369
74- xit ( 'should set "this" to undefined by default on forEach' , ( ) => {
70+ it . skip ( 'should set "this" to undefined by default on forEach' , ( ) => {
7571 const headers = new Headers ( { Accept : 'application/json' } )
7672 headers . forEach ( function ( ) {
77- expect ( this ) . to . be . undefined
73+ assert . strictEqual ( this , undefined )
7874 } )
7975 } )
8076
8177 it ( 'should accept thisArg as a second argument for forEach' , ( ) => {
8278 const headers = new Headers ( { Accept : 'application/json' } )
8379 const thisArg = { }
8480 headers . forEach ( function ( ) {
85- expect ( this ) . to . equal ( thisArg )
81+ assert . strictEqual ( this , thisArg )
8682 } , thisArg )
8783 } )
8884
@@ -93,14 +89,14 @@ describe('Headers', () => {
9389 [ 'a' , '1' ]
9490 ] )
9591 headers . append ( 'b' , '3' )
96- expect ( headers ) . to . be . iterable
92+ assert . strictEqual ( typeof headers [ Symbol . iterator ] , 'function' )
9793
9894 const result = [ ]
9995 for ( const pair of headers ) {
10096 result . push ( pair )
10197 }
10298
103- expect ( result ) . to . deep . equal ( [
99+ assert . deepStrictEqual ( result , [
104100 [ 'a' , '1' ] ,
105101 [ 'b' , '2, 3' ] ,
106102 [ 'c' , '4' ]
@@ -115,12 +111,22 @@ describe('Headers', () => {
115111 ] )
116112 headers . append ( 'b' , '3' )
117113
118- expect ( headers . entries ( ) ) . to . be . iterable
119- . and . to . deep . iterate . over ( [
120- [ 'a' , '1' ] ,
121- [ 'b' , '2, 3' ] ,
122- [ 'c' , '4' ]
123- ] )
114+ assert . strictEqual ( typeof headers . entries , 'function' )
115+ assert . strictEqual ( typeof headers . entries ( ) [ Symbol . iterator ] , 'function' )
116+
117+ const entries = headers . entries ( )
118+ assert . strictEqual ( typeof entries . next , 'function' )
119+ assert . deepStrictEqual ( entries . next ( ) . value , [ 'a' , '1' ] )
120+ assert . strictEqual ( typeof entries . next , 'function' )
121+ assert . deepStrictEqual ( entries . next ( ) . value , [ 'b' , '2, 3' ] )
122+ assert . strictEqual ( typeof entries . next , 'function' )
123+ assert . deepStrictEqual ( entries . next ( ) . value , [ 'c' , '4' ] )
124+
125+ assert . deepStrictEqual ( [ ...headers . entries ( ) ] , [
126+ [ 'a' , '1' ] ,
127+ [ 'b' , '2, 3' ] ,
128+ [ 'c' , '4' ]
129+ ] )
124130 } )
125131
126132 it ( 'should allow iterating through all headers with keys()' , ( ) => {
@@ -131,8 +137,18 @@ describe('Headers', () => {
131137 ] )
132138 headers . append ( 'b' , '3' )
133139
134- expect ( headers . keys ( ) ) . to . be . iterable
135- . and . to . iterate . over ( [ 'a' , 'b' , 'c' ] )
140+ assert . strictEqual ( typeof headers . keys , 'function' )
141+ assert . strictEqual ( typeof headers . keys ( ) [ Symbol . iterator ] , 'function' )
142+
143+ const keys = headers . keys ( )
144+ assert . strictEqual ( typeof keys . next , 'function' )
145+ assert . strictEqual ( keys . next ( ) . value , 'a' )
146+ assert . strictEqual ( typeof keys . next , 'function' )
147+ assert . strictEqual ( keys . next ( ) . value , 'b' )
148+ assert . strictEqual ( typeof keys . next , 'function' )
149+ assert . strictEqual ( keys . next ( ) . value , 'c' )
150+
151+ assert . deepStrictEqual ( [ ...headers . keys ( ) ] , [ 'a' , 'b' , 'c' ] )
136152 } )
137153
138154 it ( 'should allow iterating through all headers with values()' , ( ) => {
@@ -143,26 +159,37 @@ describe('Headers', () => {
143159 ] )
144160 headers . append ( 'b' , '3' )
145161
146- expect ( headers . values ( ) ) . to . be . iterable
147- . and . to . iterate . over ( [ '1' , '2, 3' , '4' ] )
162+ assert . strictEqual ( typeof headers . values , 'function' )
163+ assert . strictEqual ( typeof headers . values ( ) [ Symbol . iterator ] , 'function' )
164+
165+ const values = headers . values ( )
166+ assert . strictEqual ( typeof values . next , 'function' )
167+ assert . strictEqual ( values . next ( ) . value , '1' )
168+ assert . strictEqual ( typeof values . next , 'function' )
169+ assert . strictEqual ( values . next ( ) . value , '2, 3' )
170+ assert . strictEqual ( typeof values . next , 'function' )
171+ assert . strictEqual ( values . next ( ) . value , '4' )
172+
173+ assert . deepStrictEqual ( [ ...headers . values ( ) ] , [ '1' , '2, 3' , '4' ] )
148174 } )
149175
150176 it ( 'should reject illegal header' , ( ) => {
151177 const headers = new Headers ( )
152- expect ( ( ) => new Headers ( { 'He y' : 'ok' } ) ) . to . throw ( TypeError )
153- expect ( ( ) => new Headers ( { 'Hé-y' : 'ok' } ) ) . to . throw ( TypeError )
154- expect ( ( ) => new Headers ( { 'He-y' : 'ăk' } ) ) . to . throw ( TypeError )
155- expect ( ( ) => headers . append ( 'Hé-y' , 'ok' ) ) . to . throw ( TypeError )
156- expect ( ( ) => headers . delete ( 'Hé-y' ) ) . to . throw ( TypeError )
157- expect ( ( ) => headers . get ( 'Hé-y' ) ) . to . throw ( TypeError )
158- expect ( ( ) => headers . has ( 'Hé-y' ) ) . to . throw ( TypeError )
159- expect ( ( ) => headers . set ( 'Hé-y' , 'ok' ) ) . to . throw ( TypeError )
178+
179+ assert . throws ( ( ) => new Headers ( { 'He y' : 'ok' } ) , TypeError )
180+ assert . throws ( ( ) => new Headers ( { 'Hé-y' : 'ok' } ) , TypeError )
181+ assert . throws ( ( ) => new Headers ( { 'He-y' : 'ăk' } ) , TypeError )
182+ assert . throws ( ( ) => headers . append ( 'Hé-y' , 'ok' ) , TypeError )
183+ assert . throws ( ( ) => headers . delete ( 'Hé-y' ) , TypeError )
184+ assert . throws ( ( ) => headers . get ( 'Hé-y' ) , TypeError )
185+ assert . throws ( ( ) => headers . has ( 'Hé-y' ) , TypeError )
186+ assert . throws ( ( ) => headers . set ( 'Hé-y' , 'ok' ) , TypeError )
160187 // Should reject empty header
161- expect ( ( ) => headers . append ( '' , 'ok' ) ) . to . throw ( TypeError )
188+ assert . throws ( ( ) => headers . append ( '' , 'ok' ) , TypeError )
162189 } )
163190
164- xit ( 'should ignore unsupported attributes while reading headers' , ( ) => {
165- const FakeHeader = function ( ) { }
191+ it . skip ( 'should ignore unsupported attributes while reading headers' , ( ) => {
192+ const FakeHeader = function ( ) { }
166193 // Prototypes are currently ignored
167194 // This might change in the future: #181
168195 FakeHeader . prototype . z = 'fake'
@@ -188,26 +215,26 @@ describe('Headers', () => {
188215
189216 const h1Raw = h1 . raw ( )
190217
191- expect ( h1Raw . a ) . to . include ( 'string' )
192- expect ( h1Raw . b ) . to . include ( '1,2' )
193- expect ( h1Raw . c ) . to . include ( '' )
194- expect ( h1Raw . d ) . to . include ( '' )
195- expect ( h1Raw . e ) . to . include ( '1' )
196- expect ( h1Raw . f ) . to . include ( '1,2' )
197- expect ( h1Raw . g ) . to . include ( '[object Object]' )
198- expect ( h1Raw . h ) . to . include ( 'undefined' )
199- expect ( h1Raw . i ) . to . include ( 'null' )
200- expect ( h1Raw . j ) . to . include ( 'NaN' )
201- expect ( h1Raw . k ) . to . include ( 'true' )
202- expect ( h1Raw . l ) . to . include ( 'false' )
203- expect ( h1Raw . m ) . to . include ( 'test' )
204- expect ( h1Raw . n ) . to . include ( '1,2' )
205- expect ( h1Raw . n ) . to . include ( '3,4' )
206-
207- expect ( h1Raw . z ) . to . be . undefined
218+ assert . strictEqual ( h1Raw . a . includes ( 'string' ) , true )
219+ assert . strictEqual ( h1Raw . b . includes ( '1,2' ) , true )
220+ assert . strictEqual ( h1Raw . c . includes ( '' ) , true )
221+ assert . strictEqual ( h1Raw . d . includes ( '' ) , true )
222+ assert . strictEqual ( h1Raw . e . includes ( '1' ) , true )
223+ assert . strictEqual ( h1Raw . f . includes ( '1,2' ) , true )
224+ assert . strictEqual ( h1Raw . g . includes ( '[object Object]' ) , true )
225+ assert . strictEqual ( h1Raw . h . includes ( 'undefined' ) , true )
226+ assert . strictEqual ( h1Raw . i . includes ( 'null' ) , true )
227+ assert . strictEqual ( h1Raw . j . includes ( 'NaN' ) , true )
228+ assert . strictEqual ( h1Raw . k . includes ( 'true' ) , true )
229+ assert . strictEqual ( h1Raw . l . includes ( 'false' ) , true )
230+ assert . strictEqual ( h1Raw . m . includes ( 'test' ) , true )
231+ assert . strictEqual ( h1Raw . n . includes ( '1,2' ) , true )
232+ assert . strictEqual ( h1Raw . n . includes ( '3,4' ) , true )
233+
234+ assert . strictEqual ( h1Raw . z , undefined )
208235 } )
209236
210- xit ( 'should wrap headers' , ( ) => {
237+ it . skip ( 'should wrap headers' , ( ) => {
211238 const h1 = new Headers ( {
212239 a : '1'
213240 } )
@@ -221,16 +248,16 @@ describe('Headers', () => {
221248 h3 . append ( 'a' , '2' )
222249 const h3Raw = h3 . raw ( )
223250
224- expect ( h1Raw . a ) . to . include ( '1' )
225- expect ( h1Raw . a ) . to . not . include ( '2' )
251+ assert . strictEqual ( h1Raw . a . includes ( '1' ) , true )
252+ assert . strictEqual ( h1Raw . a . includes ( '2' ) , false )
226253
227- expect ( h2Raw . a ) . to . include ( '1' )
228- expect ( h2Raw . a ) . to . not . include ( '2' )
229- expect ( h2Raw . b ) . to . include ( '1' )
254+ assert . strictEqual ( h2Raw . a . includes ( '1' ) , true )
255+ assert . strictEqual ( h2Raw . a . includes ( '2' ) , false )
256+ assert . strictEqual ( h2Raw . b . includes ( '1' ) , true )
230257
231- expect ( h3Raw . a ) . to . include ( '1' )
232- expect ( h3Raw . a ) . to . include ( '2' )
233- expect ( h3Raw . b ) . to . include ( '1' )
258+ assert . strictEqual ( h3Raw . a . includes ( '1' ) , true )
259+ assert . strictEqual ( h3Raw . a . includes ( '2' ) , true )
260+ assert . strictEqual ( h3Raw . b . includes ( '1' ) , true )
234261 } )
235262
236263 it ( 'should accept headers as an iterable of tuples' , ( ) => {
@@ -241,33 +268,33 @@ describe('Headers', () => {
241268 [ 'b' , '2' ] ,
242269 [ 'a' , '3' ]
243270 ] )
244- expect ( headers . get ( 'a' ) ) . to . equal ( '1, 3' )
245- expect ( headers . get ( 'b' ) ) . to . equal ( '2' )
271+ assert . strictEqual ( headers . get ( 'a' ) , '1, 3' )
272+ assert . strictEqual ( headers . get ( 'b' ) , '2' )
246273
247274 headers = new Headers ( [
248275 new Set ( [ 'a' , '1' ] ) ,
249276 [ 'b' , '2' ] ,
250277 new Map ( [ [ 'a' , null ] , [ '3' , null ] ] ) . keys ( )
251278 ] )
252- expect ( headers . get ( 'a' ) ) . to . equal ( '1, 3' )
253- expect ( headers . get ( 'b' ) ) . to . equal ( '2' )
279+ assert . strictEqual ( headers . get ( 'a' ) , '1, 3' )
280+ assert . strictEqual ( headers . get ( 'b' ) , '2' )
254281
255282 headers = new Headers ( new Map ( [
256283 [ 'a' , '1' ] ,
257284 [ 'b' , '2' ]
258285 ] ) )
259- expect ( headers . get ( 'a' ) ) . to . equal ( '1' )
260- expect ( headers . get ( 'b' ) ) . to . equal ( '2' )
286+ assert . strictEqual ( headers . get ( 'a' ) , '1' )
287+ assert . strictEqual ( headers . get ( 'b' ) , '2' )
261288 } )
262289
263290 it ( 'should throw a TypeError if non-tuple exists in a headers initializer' , ( ) => {
264- expect ( ( ) => new Headers ( [ [ 'b' , '2' , 'huh?' ] ] ) ) . to . throw ( TypeError )
265- expect ( ( ) => new Headers ( [ 'b2' ] ) ) . to . throw ( TypeError )
266- expect ( ( ) => new Headers ( 'b2' ) ) . to . throw ( TypeError )
267- expect ( ( ) => new Headers ( { [ Symbol . iterator ] : 42 } ) ) . to . throw ( TypeError )
291+ assert . throws ( ( ) => new Headers ( [ [ 'b' , '2' , 'huh?' ] ] ) , TypeError )
292+ assert . throws ( ( ) => new Headers ( [ 'b2' ] ) , TypeError )
293+ assert . throws ( ( ) => new Headers ( 'b2' ) , TypeError )
294+ assert . throws ( ( ) => new Headers ( { [ Symbol . iterator ] : 42 } ) , TypeError )
268295 } )
269296
270- xit ( 'should use a custom inspect function' , ( ) => {
297+ it . skip ( 'should use a custom inspect function' , ( ) => {
271298 const headers = new Headers ( [
272299 [ 'Host' , 'thehost' ] ,
273300 [ 'Host' , 'notthehost' ] ,
@@ -277,6 +304,6 @@ describe('Headers', () => {
277304 ] )
278305
279306 // eslint-disable-next-line quotes
280- expect ( format ( headers ) ) . to . equal ( "{ a: [ '1', '3' ], b: '2', host: 'thehost' }" )
307+ assert . strictEqual ( format ( headers ) , "{ a: [ '1', '3' ], b: '2', host: 'thehost' }" )
281308 } )
282309} )
0 commit comments