1
1
import response from '../../src/lib/response.mjs' ;
2
2
3
3
describe ( 'response()' , ( ) => {
4
- it ( 'returns text()' , ( ) => response ( { responseText : 'A passing test.' } )
4
+ const raw = { 'x-foo' : 'foo' , 'x-bar' : 'bar' } ;
5
+ const keys = Object . keys ( raw ) ;
6
+ const all = Object . entries ( raw ) ;
7
+ const resp = response ( { } , all , keys , raw ) ;
8
+
9
+ it ( 'returns text()' , ( ) => response ( { responseText : 'A passing test.' } , [ ] , [ ] , { } )
5
10
. text ( )
6
11
. then ( ( text ) => expect ( text ) . toBe ( 'A passing test.' ) )
7
12
) ;
@@ -12,19 +17,16 @@ describe('response()', () => {
12
17
) ;
13
18
14
19
it ( 'returns headers' , ( ) => {
15
- const all = [ [ 'x-foo' , 'bar' ] , [ 'x-baz' , 'boo' ] ] ;
16
- const result = response ( { } , { all } ) . headers . entries ( ) ;
17
- expect ( result ) . toEqual ( all ) ;
20
+ expect ( resp . headers . entries ( ) ) . toEqual ( all ) ;
18
21
} ) ;
19
22
20
23
it ( 'returns header keys' , ( ) => {
21
- const result = response ( { } , { keys : [ 'x-foo' ] } ) . headers . keys ( ) ;
22
- expect ( result ) . toEqual ( [ 'x-foo' ] ) ;
24
+ expect ( resp . headers . keys ( ) ) . toEqual ( [ 'x-foo' , 'x-bar' ] ) ;
23
25
} ) ;
24
26
25
27
it ( 'returns headers has' , ( ) => {
26
- const raw = { 'x-foo' : 'bar' , 'x-baz' : 'boo' } ;
27
- const test = response ( { } , { raw } ) . headers ;
28
- expect ( test . has ( 'x-foo ' ) ) . toBe ( true ) ;
28
+ expect ( resp . headers . has ( 'x-foo' ) ) . toBe ( true ) ;
29
+ expect ( resp . headers . has ( 'x-bar' ) ) . toBe ( true ) ;
30
+ expect ( resp . headers . has ( 'x-baz ' ) ) . toBe ( false ) ;
29
31
} ) ;
30
32
} ) ;
0 commit comments