@@ -69,6 +69,26 @@ describe('Headers', () => {
6969 expect ( { key : 'content-type' , value : 'text/html' , object : headers } ) . to . deep . equal ( results [ 1 ] ) ;
7070 } ) ;
7171
72+ it ( 'should allow iterating through multiple set-cookie headers with forEach' , ( ) => {
73+ let headers = new Headers ( [
74+ [ 'a' , '1' ] ,
75+ [ 'Set-Cookie' , 'b=2' ]
76+ ] ) ;
77+ headers . append ( 'Set-Cookie' , 'c=3' ) ;
78+ expect ( headers . entries ( ) ) . to . be . iterable ;
79+
80+ const results = [ ] ;
81+ headers . forEach ( ( value , key , object ) => {
82+ results . push ( { value, key, object} ) ;
83+ } ) ;
84+
85+ expect ( results ) . to . deep . equal ( [
86+ { value : '1' , key : 'a' , object : headers } ,
87+ { value : 'b=2' , key : 'set-cookie' , object : headers } ,
88+ { value : 'c=3' , key : 'set-cookie' , object : headers } ,
89+ ] ) ;
90+ } )
91+
7292 it ( 'should set "this" to undefined by default on forEach' , ( ) => {
7393 const headers = new Headers ( { Accept : 'application/json' } ) ;
7494 headers . forEach ( function ( ) {
@@ -103,8 +123,25 @@ describe('Headers', () => {
103123 [ 'b' , '2, 3' ] ,
104124 [ 'c' , '4' ]
105125 ] ) ;
126+
106127 } ) ;
107128
129+ it ( 'should allow iterating through multiple set-cookie headers with for-of loop' , ( ) => {
130+ let headers = new Headers ( [
131+ [ 'a' , '1' ] ,
132+ [ 'Set-Cookie' , 'b=2' ]
133+ ] ) ;
134+ headers . append ( 'Set-Cookie' , 'c=3' ) ;
135+ expect ( headers . entries ( ) ) . to . be . iterable ;
136+
137+ const result = [ ] ;
138+ for ( const pair of headers ) {
139+ result . push ( pair ) ;
140+ }
141+
142+ expect ( result ) . to . deep . equal ( [ [ 'a' , '1' ] , [ 'set-cookie' , 'b=2' ] , [ 'set-cookie' , 'c=3' ] ] ) ;
143+ } )
144+
108145 it ( 'should allow iterating through all headers with entries()' , ( ) => {
109146 const headers = new Headers ( [
110147 [ 'b' , '2' ] ,
@@ -121,6 +158,16 @@ describe('Headers', () => {
121158 ] ) ;
122159 } ) ;
123160
161+ it ( 'should allow iterating through multiple set-cookie headers with entries()' , ( ) => {
162+ let headers = new Headers ( [
163+ [ 'a' , '1' ] ,
164+ [ 'Set-Cookie' , 'b=2' ]
165+ ] ) ;
166+ headers . append ( 'Set-Cookie' , 'c=3' ) ;
167+ expect ( headers . entries ( ) ) . to . be . iterable
168+ . and . to . deep . iterate . over ( [ [ 'a' , '1' ] , [ 'set-cookie' , 'b=2' ] , [ 'set-cookie' , 'c=3' ] ] ) ;
169+ } )
170+
124171 it ( 'should allow iterating through all headers with keys()' , ( ) => {
125172 const headers = new Headers ( [
126173 [ 'b' , '2' ] ,
@@ -145,6 +192,16 @@ describe('Headers', () => {
145192 . and . to . iterate . over ( [ '1' , '2, 3' , '4' ] ) ;
146193 } ) ;
147194
195+ it ( 'should allow iterating through multiple set-cookie headers with values()' , ( ) => {
196+ let headers = new Headers ( [
197+ [ 'a' , '1' ] ,
198+ [ 'Set-Cookie' , 'b=2' ]
199+ ] ) ;
200+ headers . append ( 'Set-Cookie' , 'c=3' ) ;
201+ expect ( headers . values ( ) ) . to . be . iterable
202+ . and . to . iterate . over ( [ '1' , 'b=2' , 'c=3' ] ) ;
203+ } )
204+
148205 it ( 'should reject illegal header' , ( ) => {
149206 const headers = new Headers ( ) ;
150207 expect ( ( ) => new Headers ( { 'He y' : 'ok' } ) ) . to . throw ( TypeError ) ;
0 commit comments