Coder Social home page Coder Social logo

Comments (10)

DjebbZ avatar DjebbZ commented on May 18, 2024 2

I happen to have the same problem, and found how to solve it simply.

Do as @mfrobben says, expect(SOME_CODE, done) when you don't need complete access to the error and the response.

When you need complete access to do custom stuff in the end callback, test the error as follows :

.end(function(err, res) {
  if (err) {
    done(err);
  } else {
    // do your stuff here
  }
});

I first tried without an else statement, but I got this error : Error: done() called multiple times.

from supertest.

tj avatar tj commented on May 18, 2024

hmm yeah what you expect is correct, I'll take a look

from supertest.

tj avatar tj commented on May 18, 2024

hmm i cant seem to reproduce it, my tests are fine

from supertest.

leegee avatar leegee commented on May 18, 2024

Thanks for checking. I'll try again tomorrow with a minimum test, and post the results.

from supertest.

silas avatar silas commented on May 18, 2024

I get this same behavior if I don't check for err in end and re-throw.

Example: https://gist.github.com/3722812#file_test.js

Here is a gist with a passing and failing example:

git clone git://gist.github.com/3722812.git gist-3722812

I assume this is the expected behavior, but I might be wrong.

from supertest.

mfrobben avatar mfrobben commented on May 18, 2024

bump. I'm seeing this with a test that I expect to return status 200 yet recieve 500. My call chain is as follows:

    superTest(appTest.app)
        .post(route)
        .set('Content-Type','application/json')
        .send(params)
        .expect(200)
        .end(function(err, res) {
          console.log(err) // error is returned here
          done()
        })

The mocha output (mixed with Console Log) was:
◦ POST /:uid/route with valid params should return 200:
[Error: expected 200 "OK", got 500 "Internal Server Error"]
✓ POST /:uid/route with valid params should return 200

from supertest.

mfrobben avatar mfrobben commented on May 18, 2024

TJ & Silas - FYI, this syntax fixes the issue. Hope this helps tracking down what's going on.

superTest(appTest.app)
        .post(route)
        .set('Content-Type','application/json')
        .send(params)
        .expect(200,done)

Output:
✖ 1 of 6 tests failed:

  1. POST /:uid/route with valid params should return 200:
    Error: expected 200 "OK", got 500 "Internal Server Error"

from supertest.

tj avatar tj commented on May 18, 2024

if someone can reproduce it with a pull-request test I'll take a better look, low on time ATM

from supertest.

mfrobben avatar mfrobben commented on May 18, 2024

After reading DjebbZ, this can probably be solved with documentation. Submitting a readme pull request

from supertest.

eeble avatar eeble commented on May 18, 2024

I was getting this error but it turned out it was because I wasn't separating my redirect/render code paths properly. I forgot to put a return after the redirect so it ended up redirecting then rendering on the same response object.

from supertest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.