ladjs / supertest

🕷 Super-agent driven library for testing node.js HTTP servers using a fluent API. Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTTP2 sample no working

branaway opened this issue · comments

With the latest npm module, the sample code for HTTP2 did not work:

import request from 'supertest';
import express from 'express';

const app = express();

app.get( '/user', function( req, res ) {
res.status( 200 ).json( { name: 'john' } );
} );

request( app, { http2: true } )
.get( '/user' )
.expect( 'Content-Type', /json/ )
.expect( 'Content-Length', '15' )
.expect( 200 )
.end( function( err, res ) {
if ( err ) throw err;
} );

request.agent( app, { http2: true } )
.get( '/user' )
.expect( 'Content-Type', /json/ )
.expect( 'Content-Length', '15' )
.expect( 200 )
.end( function( err, res ) {
if ( err ) throw err;
} );

This is what I saw by running the above piece of code:

➜ ~/localProjects/umxverse git:(test) ✗ node '/Users/bran/localProjects/umxverse/supertesty.js'
node:events:491
throw er; // Unhandled 'error' event
^

TypeError: Cannot read properties of undefined (reading 'readable')
at IncomingMessage.read (node:http_incoming:214:19)
at Readable.read (node:internal/streams/readable:496:12)
at resume
(node:internal/streams/readable:999:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on IncomingMessage instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at errorOrDestroy (node:internal/streams/destroy:214:7)
at Readable.read (node:internal/streams/readable:498:7)
at resume
(node:internal/streams/readable:999:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v18.11.0