1
1
import { calculateBodyLength } from "./calculateBodyLength" ;
2
2
3
- const arrayBuffer = new ArrayBuffer ( 1 ) ;
4
- const typedArray = new Uint8Array ( 1 ) ;
5
-
6
3
describe ( calculateBodyLength . name , ( ) => {
7
- it ( "should handle string inputs" , ( ) => {
8
- expect ( calculateBodyLength ( "foo" ) ) . toEqual ( 3 ) ;
4
+ describe ( "should handle string input" , ( ) => {
5
+ it . each ( [
6
+ { desc : "basic" , input : "foo" , output : 3 } ,
7
+ { desc : "emoji" , input : "foo 🥺" , output : 8 } ,
8
+ { desc : "multi-byte characters" , input : "2。" , output : 4 } ,
9
+ ] ) ( "%s" , ( { input, output } ) => {
10
+ expect ( calculateBodyLength ( input ) ) . toEqual ( output ) ;
11
+ } ) ;
9
12
} ) ;
10
13
11
- it ( "should handle string inputs with multi-byte characters" , ( ) => {
12
- expect ( calculateBodyLength ( "2。" ) ) . toEqual ( 4 ) ;
13
- } ) ;
14
+ describe ( "should handle input with byteLength" , ( ) => {
15
+ const sizes = [ 1 , 256 , 65536 ] ;
14
16
15
- it ( "should handle inputs with byteLengths" , ( ) => {
16
- expect ( calculateBodyLength ( arrayBuffer ) ) . toEqual ( 1 ) ;
17
- } ) ;
17
+ describe ( "ArrayBuffer" , ( ) => {
18
+ it . each ( sizes ) ( "size: %s" , ( size ) => {
19
+ expect ( calculateBodyLength ( new ArrayBuffer ( size ) ) ) . toEqual ( size ) ;
20
+ } ) ;
21
+ } ) ;
18
22
19
- it ( "should handle TypedArray inputs" , ( ) => {
20
- expect ( calculateBodyLength ( typedArray ) ) . toEqual ( 1 ) ;
23
+ describe ( "TypedArray" , ( ) => {
24
+ it . each ( sizes ) ( "size: %s" , ( size ) => {
25
+ expect ( calculateBodyLength ( new Uint8Array ( size ) ) ) . toEqual ( size ) ;
26
+ } ) ;
27
+ } ) ;
21
28
} ) ;
22
29
23
30
it ( "should handle File object" , ( ) => {
@@ -34,9 +41,11 @@ describe(calculateBodyLength.name, () => {
34
41
expect ( calculateBodyLength ( mockFileObject ) ) . toEqual ( mockFileObject . size ) ;
35
42
} ) ;
36
43
37
- it . each ( [ true , 1 , { } , [ ] ] ) ( "throws error if Body Length computation fails for: %s" , ( body ) => {
38
- expect ( ( ) => {
39
- expect ( calculateBodyLength ( body ) ) ;
40
- } ) . toThrowError ( `Body Length computation failed for ${ body } ` ) ;
44
+ describe ( "throws error if Body Length computation fails" , ( ) => {
45
+ it . each ( [ true , 1 , { } , [ ] ] ) ( "%s" , ( body ) => {
46
+ expect ( ( ) => {
47
+ expect ( calculateBodyLength ( body ) ) ;
48
+ } ) . toThrowError ( `Body Length computation failed for ${ body } ` ) ;
49
+ } ) ;
41
50
} ) ;
42
51
} ) ;
0 commit comments