Skip to content

Testing the response body from res.end #36

Closed
TrevorBurnham opened this Issue Nov 17, 2012 · 3 comments

2 participants

@TrevorBurnham

I'm using Mocha and Supertest to test a Connect middleware. This test succeeds:

describe('supertest', function() {

  it('matches the response body', function(done) {
    var app = new (require('express'));
    app.use(function(req, res) {
      res.send('Hi!');
    });

    request(app).get('/').expect(200, 'Hi!').end(done);
  });
});

But change res.send to res.end and it fails:

Error: expected 'Hi!' response body, got undefined

Is there a good reason why this doesn't work? I'm using connect@2.6.2 and supertest@0.4.1.

@tj
Sloth member
tj commented Nov 17, 2012

hmm it should work, on a side note you don't need new for express, just require('express')() since it's not a constructor, definitely should work, supertest / agent must not be buffering since there's no content-length, I'll see if I can patch

@tj tj added a commit that referenced this issue Nov 17, 2012
@tj tj add failing test for #36 46efc81
@tj tj closed this in 2defecb Nov 17, 2012
@TrevorBurnham

Awesome. Thanks for the quick response, TJ!

@tj
Sloth member
tj commented Nov 17, 2012

it probably used to work haha, but recent superagents changed the buffering semantics a bit :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.