@@ -27,8 +27,10 @@ describe('unfetch', () => {
2727 } ) ;
2828
2929 describe ( 'fetch()' , ( ) => {
30- it ( 'sanity test' , ( ) => {
31- let xhr = {
30+ let xhr ;
31+
32+ beforeEach ( ( ) => {
33+ xhr = {
3234 setRequestHeader : spy ( ) ,
3335 getAllResponseHeaders : stub ( ) . returns ( 'X-Foo: bar\nX-Foo:baz' ) ,
3436 open : spy ( ) ,
@@ -40,7 +42,13 @@ describe('unfetch', () => {
4042 } ;
4143
4244 global . XMLHttpRequest = stub ( ) . returns ( xhr ) ;
45+ } ) ;
4346
47+ afterEach ( ( ) => {
48+ delete global . XMLHttpRequest ;
49+ } ) ;
50+
51+ it ( 'sanity test' , ( ) => {
4452 let p = fetch ( '/foo' , { headers : { a : 'b' } } )
4553 . then ( r => {
4654 expect ( r ) . to . have . property ( 'text' ) . that . is . a ( 'function' ) ;
@@ -60,8 +68,6 @@ describe('unfetch', () => {
6068 expect ( xhr . setRequestHeader ) . to . have . been . calledOnce . and . calledWith ( 'a' , 'b' ) ;
6169 expect ( xhr . open ) . to . have . been . calledOnce . and . calledWith ( 'get' , '/foo' ) ;
6270 expect ( xhr . send ) . to . have . been . calledOnce . and . calledWith ( ) ;
63-
64- delete global . XMLHttpRequest ;
6571 } ) ;
6672
6773 expect ( xhr . onload ) . to . be . a ( 'function' ) ;
@@ -71,5 +77,18 @@ describe('unfetch', () => {
7177
7278 return p ;
7379 } ) ;
80+
81+ it ( 'handles empty header values' , ( ) => {
82+ xhr . getAllResponseHeaders = stub ( ) . returns ( 'Server: \nX-Foo:baz' ) ;
83+ let p = fetch ( '/foo' )
84+ . then ( r => {
85+ expect ( r . headers . get ( 'server' ) ) . to . equal ( '' ) ;
86+ expect ( r . headers . get ( 'X-foo' ) ) . to . equal ( 'baz' ) ;
87+ } ) ;
88+
89+ xhr . onload ( ) ;
90+
91+ return p ;
92+ } ) ;
7493 } ) ;
7594} ) ;
0 commit comments