Testing the response body from res.end #36

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

Comments

Projects
None yet
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

This comment has been minimized.

Show comment
Hide comment
@tj

tj Nov 17, 2012

Member

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

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 added a commit that referenced this issue Nov 17, 2012

@tj tj closed this in 2defecb Nov 17, 2012

@TrevorBurnham

This comment has been minimized.

Show comment
Hide comment
@TrevorBurnham

TrevorBurnham Nov 17, 2012

Awesome. Thanks for the quick response, TJ!

Awesome. Thanks for the quick response, TJ!

@tj

This comment has been minimized.

Show comment
Hide comment
@tj

tj Nov 17, 2012

Member

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

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