forwardemail / forwardemail/superagent
Uncaught TypeError: undefined is not a function
- Dominant language
- JavaScript
- Stars
- 16.6k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Looking through open and closed issues, it seems a lot of folks are having problems similar to this. Various methods fail inconsistently with `Uncaught TypeError: undefined is not a function`. Mostly PUT.
Code to reproduce is here. Failures are inconsistent. I can get it to fail roughly 20% of the time.
```
var expect = require( "chai" ).expect;
describe( "SuperAgent", function() {
var url = "http://test/foo",
request = require( "superagent" ),
server = require( "superagent-mocker" )( request );
before( function() {
server.get( url, function() {
return "get all";
});
server.post( url, function() {
return "post";
});
server.get( url + "/:id", function( req ) {
return "get " + req.params.id;
});
server.put( url + "/:id", function( req ) {
return "put " + req.params.id;
});
server.del( url + "/:id", function( req ) {
return "del " + req.params.id;
});
});
it( "GET all fails inconsistently", function( done ) {
request.get( url ).end( function( err, res ) {
expect( res ).to.equal( "get all" );
done();
});
});
it( "POST fails inconsistently", function( done ) {
request.post( url )
.set( { "Content-Type": "application/json" } )
.send( { foo: "bar" } )
.end( function( err, res ) {
expect( res ).to.equal( "post" );
done();
});
});
it( "GET fails inconsistently", function( done ) {
request.get( url + "/1" ).end( function( err, res ) {
expect( res ).to.equal( "get 1" );
done();
});
});
it( "PUT fails inconsistently", function( done ) {
request.put( url + "/1" )
.set( { "Content-Type": "application/json" } )
.send( { foo: "bar" } )
.end( function( err, res ) {
expect( res ).to.equal( "put 1" );
done();
});
});
it( "DELETE fails inconsistently", function( done ){
request.del( url + "/1" ).end( function( err, res ) {
expect( res ).to.equal( "del 1" );
done();
});
});
} );
```
Mocha reporter output after a failure:
```
SuperAgent
✓ GET all fails inconsistently
✓ POST fails inconsistently
✓ GET fails inconsistently
1) PUT fails inconsistently
✓ DELETE fails inconsistently
4 passing (25ms)
1 failing
1) SuperAgent PUT fails inconsistently:
Uncaught TypeError: undefined is not a function
at Socket.socketErrorListener (_http_client.js:271:9)
at net.js:950:16
```
Contributor guide
Research direction
Start by running the provided Mocha reproduction and repeatedly exercising the GET, POST, PUT, and DELETE cases, focusing on the intermittent PUT failure. Use the reported stack entries in _http_client.js and net.js as the first debugging points. Done means the reproduction completes reliably without the uncaught TypeError and all expected responses are returned.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100