question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

double callback! warning

See original GitHub issue

I noticed I was getting a double callback warning in quite a few of my tests using supertest.

I found the issue was with how I was using expect and end as follows

request(app)
  .get('/something')
  .expect(200, function (res) {
    // some logic
    return false
  })
  .end(done);

Changing that to the following resolved the issue for me

request(app)
  .get('/something')
  .expect(function (res) {
    // some logic
    return false;
  })
  .expect(200, done);

To see the double callback warning, see this example

Note that this is using express 4.4.1 and supertest 0.13.0

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
vuesomedevcommented, Sep 21, 2016

Just need to remove the .end() call from the request and handle the returned Promise.

This should be documented, really confusing with co-supertest. https://github.com/avbel/co-supertest/issues/9

2reactions
n0m0r3pa1ncommented, May 14, 2016

I think I get an error connected with this question. Here is my test:

it 'should login user', ->
    createUser("gmirchev90", "1234")
    request(sails.hooks.http.app)
      .post("/api/login")
      .send({username: "gmirchev90", password: "1234"})
      .end (err, res) ->
        console.log(err);
// I get an exception:
// TypeError: First argument must be a string or Buffer

but if I change it with:

request(sails.hooks.http.app)
      .post("/api/login")
      .send({username: "gmirchev90", password: "1234"})
      .expect(200)

Now everything works. Even if I set a wrong code like 400 I get an exception that I got 200 instead of 400. Is this connected with this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue #141 · ladjs/supertest - double callback! warning - GitHub
I noticed I was getting a double callback warning in quite a few of my tests using supertest. I found the issue was...
Read more >
node.js - Chai http - double callback issue - Stack Overflow
catch() are getting called, resulting in the done callback being called twice. Here's a solution using .then/.catch , combined with Mocha's ...
Read more >
Debugging double-callback bugs in node.js
Our callback gets called twice – which isn't so bad with things that don't care like console. log and console. warn , but...
Read more >
Callbacks in App Designer - MATLAB & Simulink - MathWorks
Write callbacks to control the behavior of apps you create in App Designer. ... For example, sliders have two callback properties: ValueChangedFcn and ......
Read more >
How to prevent disasters caused by the callback getting called ...
I guess you could set a flag when you send the callback function, clear it the first callback, and then ignore the callback...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found