@@ -17,8 +17,7 @@ export class MockRequest implements Request {
1717 readonly destination : RequestDestination = "" ;
1818 readonly isHistoryNavigation : boolean = false ;
1919 readonly isReloadNavigation : boolean = false ;
20- // @ts -expect-error
21- readonly body : ReadableStream < Uint8Array > | null ;
20+ readonly body : ReadableStream < Uint8Array < ArrayBuffer > > | null ;
2221 #bytes: Uint8Array | null ;
2322
2423 constructor ( input : RequestInfo | URL , init ?: RequestInit ) {
@@ -62,9 +61,12 @@ export class MockRequest implements Request {
6261 }
6362
6463 this . body = this . #bytes
65- ? new ReadableStream < Uint8Array > ( {
64+ ? new ReadableStream < Uint8Array < ArrayBuffer > > ( {
6665 start : ( controller ) => {
67- controller . enqueue ( this . #bytes! ) ;
66+ const buffer = new ArrayBuffer ( this . #bytes! . byteLength ) ;
67+ const view = new Uint8Array ( buffer ) ;
68+ view . set ( this . #bytes! ) ;
69+ controller . enqueue ( view ) ;
6870 controller . close ( ) ;
6971 } ,
7072 pull : ( ) => {
@@ -124,9 +126,18 @@ export class MockRequest implements Request {
124126 return this . #bytes ? new TextDecoder ( ) . decode ( this . #bytes) : "" ;
125127 }
126128
129+ async bytes ( ) : Promise < Uint8Array < ArrayBuffer > > {
130+ if ( this . bodyUsed ) throw new TypeError ( "Body already consumed" ) ;
131+ ( this as any ) . bodyUsed = true ;
132+ if ( ! this . #bytes) return new Uint8Array ( new ArrayBuffer ( 0 ) ) ;
133+ const buffer = new ArrayBuffer ( this . #bytes. byteLength ) ;
134+ const view = new Uint8Array ( buffer ) ;
135+ view . set ( this . #bytes) ;
136+ return view ;
137+ }
138+
127139 clone ( ) : Request {
128140 if ( this . bodyUsed ) throw new TypeError ( "Cannot clone: Body already consumed" ) ;
129- // @ts -expect-error
130141 return new MockRequest ( this , {
131142 method : this . method ,
132143 headers : this . headers ,
0 commit comments