@@ -32,8 +32,8 @@ const partToTestPart = async (part: Part) => {
3232const getTestParts = async ( stream : ReadableStream , boundary : string ) => {
3333 const actualParts = await getParts ( stream , boundary ) ;
3434 const testPartsPromises = actualParts . map ( partToTestPart ) ;
35- const testParts = await Promise . all ( testPartsPromises ) ;
36- return testParts ;
35+
36+ return Promise . all ( testPartsPromises ) ;
3737} ;
3838
3939const headersToString = ( headers : { readonly [ key : string ] : string } ) : string => {
@@ -180,19 +180,28 @@ describe('expressPresenter/utils/getParts', () => {
180180
181181 it ( 'should throw error when there is an error in the stream' , async ( ) => {
182182 const stream = new ReadableStream ( ) ;
183- const error = new Error ( ) ;
184- try {
185- stream . push ( 'hello' ) ;
186- stream . emit ( 'error' , error ) ;
187- } catch {
188- // Do nothing.
189- }
183+ stream . _read = ( ) => true ;
184+
185+ const error = new Error ( 'Test stream error' ) ;
186+ const errorEmitDelayMs = 50 ;
187+
190188 try {
191- await getTestParts ( stream , TEST_BOUNDARY ) ;
192- /* istanbul ignore next */
193- assert . fail ( 'Expected error to be thrown.' ) ;
194- } catch {
195- // Do nothing.
189+ await Promise . all ( [
190+ getTestParts ( stream , TEST_BOUNDARY ) ,
191+ new Promise < void > ( ( resolve ) => {
192+ setTimeout ( ( ) => {
193+ stream . emit ( 'error' , error ) ;
194+
195+ resolve ( ) ;
196+ } , errorEmitDelayMs ) ;
197+ } ) ,
198+ ] ) ;
199+ } catch ( e ) {
200+ assert . deepEqual ( e , error ) ;
201+
202+ return ;
196203 }
204+
205+ assert . fail ( `Error "${ error . message } " should have thrown` ) ;
197206 } ) ;
198207} ) ;
0 commit comments