@@ -69,6 +69,26 @@ describe('Headers', () => {
69
69
expect ( { key : 'content-type' , value : 'text/html' , object : headers } ) . to . deep . equal ( results [ 1 ] ) ;
70
70
} ) ;
71
71
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
+
72
92
it ( 'should set "this" to undefined by default on forEach' , ( ) => {
73
93
const headers = new Headers ( { Accept : 'application/json' } ) ;
74
94
headers . forEach ( function ( ) {
@@ -103,8 +123,25 @@ describe('Headers', () => {
103
123
[ 'b' , '2, 3' ] ,
104
124
[ 'c' , '4' ]
105
125
] ) ;
126
+
106
127
} ) ;
107
128
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
+
108
145
it ( 'should allow iterating through all headers with entries()' , ( ) => {
109
146
const headers = new Headers ( [
110
147
[ 'b' , '2' ] ,
@@ -121,6 +158,16 @@ describe('Headers', () => {
121
158
] ) ;
122
159
} ) ;
123
160
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
+
124
171
it ( 'should allow iterating through all headers with keys()' , ( ) => {
125
172
const headers = new Headers ( [
126
173
[ 'b' , '2' ] ,
@@ -145,6 +192,16 @@ describe('Headers', () => {
145
192
. and . to . iterate . over ( [ '1' , '2, 3' , '4' ] ) ;
146
193
} ) ;
147
194
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
+
148
205
it ( 'should reject illegal header' , ( ) => {
149
206
const headers = new Headers ( ) ;
150
207
expect ( ( ) => new Headers ( { 'He y' : 'ok' } ) ) . to . throw ( TypeError ) ;
0 commit comments